<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qimage.cpp -->
  <title>QImage Class | Qt GUI 5.14.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QImage</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#related-non-members">Related Non-Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#reading-and-writing-image-files">Reading and Writing Image Files</a></li>
<li class="level2"><a href="#image-information">Image Information</a></li>
<li class="level2"><a href="#pixel-manipulation">Pixel Manipulation</a></li>
<li class="level2"><a href="#image-formats">Image Formats</a></li>
<li class="level2"><a href="#image-transformations">Image Transformations</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QImage Class</h1>
<!-- $$$QImage-brief -->
<p>The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device. <a href="#details">More...</a></p>
<!-- @@@QImage -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QImage&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qpaintdevice.html">QPaintDevice</a></td></tr></table></div><ul>
<li><a href="qimage-members.html">List of all members, including inherited members</a></li>
<li><a href="qimage-obsolete.html">Obsolete members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are <a href="../qtdoc/threads-reentrancy.html">reentrant</a>.</p>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#Format-enum">Format</a></b> { Format_Invalid, Format_Mono, Format_MonoLSB, Format_Indexed8, Format_RGB32, &hellip;, Format_BGR888 }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#InvertMode-enum">InvertMode</a></b> { InvertRgb, InvertRgba }</td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-10">QImage</a></b>(QImage &amp;&amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-9">QImage</a></b>(const QImage &amp;<i>image</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-8">QImage</a></b>(const QString &amp;<i>fileName</i>, const char *<i>format</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-7">QImage</a></b>(const char *const [] <i>xpm</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-6">QImage</a></b>(const uchar *<i>data</i>, int <i>width</i>, int <i>height</i>, int <i>bytesPerLine</i>, QImage::Format <i>format</i>, QImageCleanupFunction <i>cleanupFunction</i> = nullptr, void *<i>cleanupInfo</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-5">QImage</a></b>(uchar *<i>data</i>, int <i>width</i>, int <i>height</i>, int <i>bytesPerLine</i>, QImage::Format <i>format</i>, QImageCleanupFunction <i>cleanupFunction</i> = nullptr, void *<i>cleanupInfo</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-4">QImage</a></b>(const uchar *<i>data</i>, int <i>width</i>, int <i>height</i>, QImage::Format <i>format</i>, QImageCleanupFunction <i>cleanupFunction</i> = nullptr, void *<i>cleanupInfo</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-3">QImage</a></b>(uchar *<i>data</i>, int <i>width</i>, int <i>height</i>, QImage::Format <i>format</i>, QImageCleanupFunction <i>cleanupFunction</i> = nullptr, void *<i>cleanupInfo</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-2">QImage</a></b>(int <i>width</i>, int <i>height</i>, QImage::Format <i>format</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage-1">QImage</a></b>(const QSize &amp;<i>size</i>, QImage::Format <i>format</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImage">QImage</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage &amp;</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#operator-eq-1">operator=</a></b>(QImage &amp;&amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage &amp;</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#operator-eq">operator=</a></b>(const QImage &amp;<i>image</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#dtor.QImage">~QImage</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#allGray">allGray</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#applyColorTransform">applyColorTransform</a></b>(const QColorTransform &amp;<i>transform</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#bitPlaneCount">bitPlaneCount</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> uchar *</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#bits">bits</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const uchar *</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#bits-1">bits</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#bytesPerLine">bytesPerLine</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#cacheKey">cacheKey</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QRgb </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#color">color</a></b>(int <i>i</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#colorCount">colorCount</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QColorSpace </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#colorSpace">colorSpace</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QVector&lt;QRgb&gt; </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#colorTable">colorTable</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const uchar *</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#constBits">constBits</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const uchar *</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#constScanLine">constScanLine</a></b>(int <i>i</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#convertTo">convertTo</a></b>(QImage::Format <i>format</i>, Qt::ImageConversionFlags <i>flags</i> = Qt::AutoColor)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#convertToColorSpace">convertToColorSpace</a></b>(const QColorSpace &amp;<i>colorSpace</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#convertToFormat">convertToFormat</a></b>(QImage::Format <i>format</i>, Qt::ImageConversionFlags <i>flags</i> = Qt::AutoColor) const &</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#convertToFormat-1">convertToFormat</a></b>(QImage::Format <i>format</i>, Qt::ImageConversionFlags <i>flags</i> = Qt::AutoColor) &&</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#convertToFormat-2">convertToFormat</a></b>(QImage::Format <i>format</i>, const QVector&lt;QRgb&gt; &amp;<i>colorTable</i>, Qt::ImageConversionFlags <i>flags</i> = Qt::AutoColor) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#convertedToColorSpace">convertedToColorSpace</a></b>(const QColorSpace &amp;<i>colorSpace</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#copy">copy</a></b>(const QRect &amp;<i>rectangle</i> = QRect()) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#copy-1">copy</a></b>(int <i>x</i>, int <i>y</i>, int <i>width</i>, int <i>height</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#createAlphaMask">createAlphaMask</a></b>(Qt::ImageConversionFlags <i>flags</i> = Qt::AutoColor) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#createHeuristicMask">createHeuristicMask</a></b>(bool <i>clipTight</i> = true) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#createMaskFromColor">createMaskFromColor</a></b>(QRgb <i>color</i>, Qt::MaskMode <i>mode</i> = Qt::MaskInColor) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#depth">depth</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qreal </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#devicePixelRatio">devicePixelRatio</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#dotsPerMeterX">dotsPerMeterX</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#dotsPerMeterY">dotsPerMeterY</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#fill">fill</a></b>(uint <i>pixelValue</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#fill-1">fill</a></b>(const QColor &amp;<i>color</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#fill-2">fill</a></b>(Qt::GlobalColor <i>color</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage::Format </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#format">format</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#hasAlphaChannel">hasAlphaChannel</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#height">height</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#invertPixels">invertPixels</a></b>(QImage::InvertMode <i>mode</i> = InvertRgb)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#isGrayscale">isGrayscale</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#isNull">isNull</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#load">load</a></b>(const QString &amp;<i>fileName</i>, const char *<i>format</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#load-1">load</a></b>(QIODevice *<i>device</i>, const char *<i>format</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#loadFromData">loadFromData</a></b>(const uchar *<i>data</i>, int <i>len</i>, const char *<i>format</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#loadFromData-1">loadFromData</a></b>(const QByteArray &amp;<i>data</i>, const char *<i>format</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#mirrored">mirrored</a></b>(bool <i>horizontal</i> = ..., bool <i>vertical</i> = ...) const &</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage &amp;&amp;</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#mirrored-1">mirrored</a></b>(bool <i>horizontal</i> = ..., bool <i>vertical</i> = ...) &&</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPoint </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#offset">offset</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QRgb </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#pixel">pixel</a></b>(const QPoint &amp;<i>position</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QRgb </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#pixel-1">pixel</a></b>(int <i>x</i>, int <i>y</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QColor </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#pixelColor">pixelColor</a></b>(const QPoint &amp;<i>position</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QColor </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#pixelColor-1">pixelColor</a></b>(int <i>x</i>, int <i>y</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPixelFormat </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#pixelFormat">pixelFormat</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#pixelIndex">pixelIndex</a></b>(const QPoint &amp;<i>position</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#pixelIndex-1">pixelIndex</a></b>(int <i>x</i>, int <i>y</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QRect </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#rect">rect</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#reinterpretAsFormat">reinterpretAsFormat</a></b>(QImage::Format <i>format</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#rgbSwapped">rgbSwapped</a></b>() const &</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage &amp;&amp;</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#rgbSwapped-1">rgbSwapped</a></b>() &&</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#save">save</a></b>(const QString &amp;<i>fileName</i>, const char *<i>format</i> = nullptr, int <i>quality</i> = -1) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#save-1">save</a></b>(QIODevice *<i>device</i>, const char *<i>format</i> = nullptr, int <i>quality</i> = -1) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#scaled">scaled</a></b>(const QSize &amp;<i>size</i>, Qt::AspectRatioMode <i>aspectRatioMode</i> = Qt::IgnoreAspectRatio, Qt::TransformationMode <i>transformMode</i> = Qt::FastTransformation) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#scaled-1">scaled</a></b>(int <i>width</i>, int <i>height</i>, Qt::AspectRatioMode <i>aspectRatioMode</i> = Qt::IgnoreAspectRatio, Qt::TransformationMode <i>transformMode</i> = Qt::FastTransformation) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#scaledToHeight">scaledToHeight</a></b>(int <i>height</i>, Qt::TransformationMode <i>mode</i> = Qt::FastTransformation) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#scaledToWidth">scaledToWidth</a></b>(int <i>width</i>, Qt::TransformationMode <i>mode</i> = Qt::FastTransformation) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> uchar *</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#scanLine">scanLine</a></b>(int <i>i</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const uchar *</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#scanLine-1">scanLine</a></b>(int <i>i</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setColor">setColor</a></b>(int <i>index</i>, QRgb <i>colorValue</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setColorCount">setColorCount</a></b>(int <i>colorCount</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setColorSpace">setColorSpace</a></b>(const QColorSpace &amp;<i>colorSpace</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setColorTable">setColorTable</a></b>(const QVector&lt;QRgb&gt; <i>colors</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setDevicePixelRatio">setDevicePixelRatio</a></b>(qreal <i>scaleFactor</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setDotsPerMeterX">setDotsPerMeterX</a></b>(int <i>x</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setDotsPerMeterY">setDotsPerMeterY</a></b>(int <i>y</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setOffset">setOffset</a></b>(const QPoint &amp;<i>offset</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setPixel">setPixel</a></b>(const QPoint &amp;<i>position</i>, uint <i>index_or_rgb</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setPixel-1">setPixel</a></b>(int <i>x</i>, int <i>y</i>, uint <i>index_or_rgb</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setPixelColor">setPixelColor</a></b>(const QPoint &amp;<i>position</i>, const QColor &amp;<i>color</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setPixelColor-1">setPixelColor</a></b>(int <i>x</i>, int <i>y</i>, const QColor &amp;<i>color</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#setText">setText</a></b>(const QString &amp;<i>key</i>, const QString &amp;<i>text</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSize </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#size">size</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qsizetype </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#sizeInBytes">sizeInBytes</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#swap">swap</a></b>(QImage &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#text">text</a></b>(const QString &amp;<i>key</i> = QString()) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#textKeys">textKeys</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> CGImageRef </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#toCGImage">toCGImage</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#transformed">transformed</a></b>(const QMatrix &amp;<i>matrix</i>, Qt::TransformationMode <i>mode</i> = Qt::FastTransformation) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#transformed-1">transformed</a></b>(const QTransform &amp;<i>matrix</i>, Qt::TransformationMode <i>mode</i> = Qt::FastTransformation) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#valid">valid</a></b>(const QPoint &amp;<i>pos</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#valid-1">valid</a></b>(int <i>x</i>, int <i>y</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#width">width</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QVariant </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#operator-QVariant">operator QVariant</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#operator-not-eq">operator!=</a></b>(const QImage &amp;<i>image</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#operator-eq-eq">operator==</a></b>(const QImage &amp;<i>image</i>) const</td></tr>
</table></div>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#fromData">fromData</a></b>(const uchar *<i>data</i>, int <i>size</i>, const char *<i>format</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#fromData-1">fromData</a></b>(const QByteArray &amp;<i>data</i>, const char *<i>format</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage::Format </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#toImageFormat">toImageFormat</a></b>(QPixelFormat <i>format</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPixelFormat </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#toPixelFormat">toPixelFormat</a></b>(QImage::Format <i>format</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QMatrix </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#trueMatrix">trueMatrix</a></b>(const QMatrix &amp;<i>matrix</i>, int <i>width</i>, int <i>height</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTransform </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#trueMatrix-1">trueMatrix</a></b>(const QTransform &amp;<i>matrix</i>, int <i>width</i>, int <i>height</i>)</td></tr>
</table></div>
<a name="protected-functions"></a>
<h2 id="protected-functions">Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#smoothScaled">smoothScaled</a></b>(int <i>w</i>, int <i>h</i>) const</td></tr>
</table></div>
<a name="related-non-members"></a>
<h2 id="related-non-members">Related Non-Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qimage.html#QImageCleanupFunction-typedef">QImageCleanupFunction</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp;</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#operator-lt-lt-23">operator&lt;&lt;</a></b>(QDataStream &amp;<i>stream</i>, const QImage &amp;<i>image</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp;</td><td class="memItemRight bottomAlign"><b><a href="qimage.html#operator-gt-gt">operator&gt;&gt;</a></b>(QDataStream &amp;<i>stream</i>, QImage &amp;<i>image</i>)</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QImage-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>Qt provides four classes for handling image data: QImage, <a href="qpixmap.html">QPixmap</a>, <a href="qbitmap.html">QBitmap</a> and <a href="qpicture.html">QPicture</a>. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while <a href="qpixmap.html">QPixmap</a> is designed and optimized for showing images on screen. <a href="qbitmap.html">QBitmap</a> is only a convenience class that inherits <a href="qpixmap.html">QPixmap</a>, ensuring a depth of 1. Finally, the <a href="qpicture.html">QPicture</a> class is a paint device that records and replays <a href="qpainter.html">QPainter</a> commands.</p>
<p>Because QImage is a <a href="qpaintdevice.html">QPaintDevice</a> subclass, <a href="qpainter.html">QPainter</a> can be used to draw directly onto images. When using <a href="qpainter.html">QPainter</a> on a QImage, the painting can be performed in another thread than the current GUI thread.</p>
<p>The QImage class supports several image formats described by the <a href="qimage.html#Format-enum">Format</a> enum. These include monochrome, 8-bit, 32-bit and alpha-blended images which are available in all versions of Qt 4.x&#x2e;</p>
<p>QImage provides a collection of functions that can be used to obtain a variety of information about the image. There are also several functions that enables transformation of the image.</p>
<p>QImage objects can be passed around by value since the QImage class uses <a href="../qtcore/implicit-sharing.html">implicit data sharing</a>. QImage objects can also be streamed and compared.</p>
<p><b>Note: </b>If you would like to load QImage objects in a static build of Qt, refer to the <a href="../qtdoc/plugins-howto.html">Plugin HowTo</a>.</p><p><b>Warning:</b> Painting on a QImage with the format <a href="qimage.html#Format-enum">QImage::Format_Indexed8</a> is not supported.</p>
<a name="reading-and-writing-image-files"></a>
<h3 id="reading-and-writing-image-files">Reading and Writing Image Files</h3>
<p>QImage provides several ways of loading an image file: The file can be loaded when constructing the QImage object, or by using the <a href="qimage.html#load">load</a>() or <a href="qimage.html#loadFromData">loadFromData</a>() functions later on. QImage also provides the static <a href="qimage.html#fromData">fromData</a>() function, constructing a QImage from the given data. When loading an image, the file name can either refer to an actual file on disk or to one of the application's embedded resources. See <a href="../qtcore/resources.html">The Qt Resource System</a> overview for details on how to embed images and other resource files in the application's executable.</p>
<p>Simply call the <a href="qimage.html#save">save</a>() function to save a QImage object.</p>
<p>The complete list of supported file formats are available through the <a href="qimagereader.html#supportedImageFormats">QImageReader::supportedImageFormats</a>() and <a href="qimagewriter.html#supportedImageFormats">QImageWriter::supportedImageFormats</a>() functions. New file formats can be added as plugins. By default, Qt supports the following formats:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Format</th><th >Description</th><th >Qt's support</th></tr></thead>
<tr valign="top" class="odd"><td >BMP</td><td >Windows Bitmap</td><td >Read/write</td></tr>
<tr valign="top" class="even"><td >GIF</td><td >Graphic Interchange Format (optional)</td><td >Read</td></tr>
<tr valign="top" class="odd"><td >JPG</td><td >Joint Photographic Experts Group</td><td >Read/write</td></tr>
<tr valign="top" class="even"><td >JPEG</td><td >Joint Photographic Experts Group</td><td >Read/write</td></tr>
<tr valign="top" class="odd"><td >PNG</td><td >Portable Network Graphics</td><td >Read/write</td></tr>
<tr valign="top" class="even"><td >PBM</td><td >Portable Bitmap</td><td >Read</td></tr>
<tr valign="top" class="odd"><td >PGM</td><td >Portable Graymap</td><td >Read</td></tr>
<tr valign="top" class="even"><td >PPM</td><td >Portable Pixmap</td><td >Read/write</td></tr>
<tr valign="top" class="odd"><td >XBM</td><td >X11 Bitmap</td><td >Read/write</td></tr>
<tr valign="top" class="even"><td >XPM</td><td >X11 Pixmap</td><td >Read/write</td></tr>
</table></div>
<a name="image-information"></a>
<h3 id="image-information">Image Information</h3>
<p>QImage provides a collection of functions that can be used to obtain a variety of information about the image:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th ></th><th >Available Functions</th></tr></thead>
<tr valign="top" class="odd"><td >Geometry</td><td >The <a href="qimage.html#size">size</a>(), <a href="qimage.html#width">width</a>(), <a href="qimage.html#height">height</a>(), <a href="qimage.html#dotsPerMeterX">dotsPerMeterX</a>(), and <a href="qimage.html#dotsPerMeterY">dotsPerMeterY</a>() functions provide information about the image size and aspect ratio.<p>The <a href="qimage.html#rect">rect</a>() function returns the image's enclosing rectangle. The <a href="qimage.html#valid">valid</a>() function tells if a given pair of coordinates is within this rectangle. The <a href="qimage.html#offset">offset</a>() function returns the number of pixels by which the image is intended to be offset by when positioned relative to other images, which also can be manipulated using the <a href="qimage.html#setOffset">setOffset</a>() function.</p>
</td></tr>
<tr valign="top" class="even"><td >Colors</td><td >The color of a pixel can be retrieved by passing its coordinates to the <a href="qimage.html#pixel">pixel</a>() function. The <a href="qimage.html#pixel">pixel</a>() function returns the color as a <a href="qcolor.html#QRgb-typedef">QRgb</a> value indepedent of the image's format.<p>In case of monochrome and 8-bit images, the <a href="qimage.html#colorCount">colorCount</a>() and <a href="qimage.html#colorTable">colorTable</a>() functions provide information about the color components used to store the image data: The <a href="qimage.html#colorTable">colorTable</a>() function returns the image's entire color table. To obtain a single entry, use the <a href="qimage.html#pixelIndex">pixelIndex</a>() function to retrieve the pixel index for a given pair of coordinates, then use the <a href="qimage.html#color">color</a>() function to retrieve the color. Note that if you create an 8-bit image manually, you have to set a valid color table on the image as well.</p>
<p>The <a href="qimage.html#hasAlphaChannel">hasAlphaChannel</a>() function tells if the image's format respects the alpha channel, or not. The <a href="qimage.html#allGray">allGray</a>() and <a href="qimage.html#isGrayscale">isGrayscale</a>() functions tell whether an image's colors are all shades of gray.</p>
<p>See also the <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a> and <a href="qimage.html#image-transformations">Image Transformations</a> sections.</p>
</td></tr>
<tr valign="top" class="odd"><td >Text</td><td >The <a href="qimage.html#text">text</a>() function returns the image text associated with the given text key. An image's text keys can be retrieved using the <a href="qimage.html#textKeys">textKeys</a>() function. Use the <a href="qimage.html#setText">setText</a>() function to alter an image's text.</td></tr>
<tr valign="top" class="even"><td >Low-level information</td><td >The <a href="qimage.html#depth">depth</a>() function returns the depth of the image. The supported depths are 1 (monochrome), 8, 16, 24 and 32 bits. The <a href="qimage.html#bitPlaneCount">bitPlaneCount</a>() function tells how many of those bits that are used. For more information see the <a href="qimage.html#image-formats">Image Formats</a> section.<p>The <a href="qimage.html#format">format</a>(), <a href="qimage.html#bytesPerLine">bytesPerLine</a>(), and <a href="qimage.html#sizeInBytes">sizeInBytes</a>() functions provide low-level information about the data stored in the image.</p>
<p>The <a href="qimage.html#cacheKey">cacheKey</a>() function returns a number that uniquely identifies the contents of this QImage object.</p>
</td></tr>
</table></div>
<a name="pixel-manipulation"></a>
<h3 id="pixel-manipulation">Pixel Manipulation</h3>
<p>The functions used to manipulate an image's pixels depend on the image format. The reason is that monochrome and 8-bit images are index-based and use a color lookup table, while 32-bit images store ARGB values directly. For more information on image formats, see the <a href="qimage.html#image-formats">Image Formats</a> section.</p>
<p>In case of a 32-bit image, the <a href="qimage.html#setPixel">setPixel</a>() function can be used to alter the color of the pixel at the given coordinates to any other color specified as an ARGB quadruplet. To make a suitable <a href="qcolor.html#QRgb-typedef">QRgb</a> value, use the <a href="qcolor.html#qRgb">qRgb</a>() (adding a default alpha component to the given RGB values, i.e&#x2e; creating an opaque color) or <a href="qcolor.html#qRgba">qRgba</a>() function. For example:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th  colspan="2">32-bit</th></tr></thead>
<tr valign="top" class="odd"><td ><img src="images/qimage-32bit_scaled.png" alt="" /></td><td ><pre class="cpp">

  <span class="type"><a href="qimage.html#QImage">QImage</a></span> image(<span class="number">3</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="type"><a href="qimage.html#QImage">QImage</a></span><span class="operator">::</span>Format_RGB32);
  <span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span> value;

  value <span class="operator">=</span> <a href="qcolor.html#qRgb">qRgb</a>(<span class="number">189</span><span class="operator">,</span> <span class="number">149</span><span class="operator">,</span> <span class="number">39</span>); <span class="comment">// 0xffbd9527</span>
  image<span class="operator">.</span>setPixel(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> value);

  value <span class="operator">=</span> <a href="qcolor.html#qRgb">qRgb</a>(<span class="number">122</span><span class="operator">,</span> <span class="number">163</span><span class="operator">,</span> <span class="number">39</span>); <span class="comment">// 0xff7aa327</span>
  image<span class="operator">.</span>setPixel(<span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> value);
  image<span class="operator">.</span>setPixel(<span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> value);

  value <span class="operator">=</span> <a href="qcolor.html#qRgb">qRgb</a>(<span class="number">237</span><span class="operator">,</span> <span class="number">187</span><span class="operator">,</span> <span class="number">51</span>); <span class="comment">// 0xffedba31</span>
  image<span class="operator">.</span>setPixel(<span class="number">2</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> value);

</pre>
</td></tr>
</table></div>
<p>In case of a 8-bit and monchrome images, the pixel value is only an index from the image's color table. So the <a href="qimage.html#setPixel">setPixel</a>() function can only be used to alter the color of the pixel at the given coordinates to a predefined color from the image's color table, i.e&#x2e; it can only change the pixel's index value. To alter or add a color to an image's color table, use the <a href="qimage.html#setColor">setColor</a>() function.</p>
<p>An entry in the color table is an ARGB quadruplet encoded as an <a href="qcolor.html#QRgb-typedef">QRgb</a> value. Use the <a href="qcolor.html#qRgb">qRgb</a>() and <a href="qcolor.html#qRgba">qRgba</a>() functions to make a suitable <a href="qcolor.html#QRgb-typedef">QRgb</a> value for use with the <a href="qimage.html#setColor">setColor</a>() function. For example:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th  colspan="2">8-bit</th></tr></thead>
<tr valign="top" class="odd"><td ><img src="images/qimage-8bit_scaled.png" alt="" /></td><td ><pre class="cpp">

  <span class="type"><a href="qimage.html#QImage">QImage</a></span> image(<span class="number">3</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="type"><a href="qimage.html#QImage">QImage</a></span><span class="operator">::</span>Format_Indexed8);
  <span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span> value;

  value <span class="operator">=</span> <a href="qcolor.html#qRgb">qRgb</a>(<span class="number">122</span><span class="operator">,</span> <span class="number">163</span><span class="operator">,</span> <span class="number">39</span>); <span class="comment">// 0xff7aa327</span>
  image<span class="operator">.</span>setColor(<span class="number">0</span><span class="operator">,</span> value);

  value <span class="operator">=</span> <a href="qcolor.html#qRgb">qRgb</a>(<span class="number">237</span><span class="operator">,</span> <span class="number">187</span><span class="operator">,</span> <span class="number">51</span>); <span class="comment">// 0xffedba31</span>
  image<span class="operator">.</span>setColor(<span class="number">1</span><span class="operator">,</span> value);

  value <span class="operator">=</span> <a href="qcolor.html#qRgb">qRgb</a>(<span class="number">189</span><span class="operator">,</span> <span class="number">149</span><span class="operator">,</span> <span class="number">39</span>); <span class="comment">// 0xffbd9527</span>
  image<span class="operator">.</span>setColor(<span class="number">2</span><span class="operator">,</span> value);

  image<span class="operator">.</span>setPixel(<span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
  image<span class="operator">.</span>setPixel(<span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
  image<span class="operator">.</span>setPixel(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
  image<span class="operator">.</span>setPixel(<span class="number">2</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);

</pre>
</td></tr>
</table></div>
<p>For images with more than 8-bit per color-channel. The methods <a href="qimage.html#setPixelColor">setPixelColor</a>() and <a href="qimage.html#pixelColor">pixelColor</a>() can be used to set and get with <a href="qcolor.html">QColor</a> values.</p>
<p>QImage also provide the <a href="qimage.html#scanLine">scanLine</a>() function which returns a pointer to the pixel data at the scanline with the given index, and the <a href="qimage.html#bits">bits</a>() function which returns a pointer to the first pixel data (this is equivalent to <code>scanLine(0)</code>).</p>
<a name="image-formats"></a>
<h3 id="image-formats">Image Formats</h3>
<p>Each pixel stored in a QImage is represented by an integer. The size of the integer varies depending on the format. QImage supports several image formats described by the <a href="qimage.html#Format-enum">Format</a> enum.</p>
<p>Monochrome images are stored using 1-bit indexes into a color table with at most two colors. There are two different types of monochrome images: big endian (MSB first) or little endian (LSB first) bit order.</p>
<p>8-bit images are stored using 8-bit indexes into a color table, i.e&#x2e; they have a single byte per pixel. The color table is a <a href="../qtcore/qvector.html">QVector</a>&lt;<a href="qcolor.html#QRgb-typedef">QRgb</a>&gt;, and the <a href="qcolor.html#QRgb-typedef">QRgb</a> typedef is equivalent to an unsigned int containing an ARGB quadruplet on the format 0xAARRGGBB.</p>
<p>32-bit images have no color table; instead, each pixel contains an <a href="qcolor.html#QRgb-typedef">QRgb</a> value. There are three different types of 32-bit images storing RGB (i.e&#x2e; 0xffRRGGBB), ARGB and premultiplied ARGB values respectively. In the premultiplied format the red, green, and blue channels are multiplied by the alpha component divided by 255.</p>
<p>An image's format can be retrieved using the <a href="qimage.html#format">format</a>() function. Use the <a href="qimage.html#convertToFormat">convertToFormat</a>() functions to convert an image into another format. The <a href="qimage.html#allGray">allGray</a>() and <a href="qimage.html#isGrayscale">isGrayscale</a>() functions tell whether a color image can safely be converted to a grayscale image.</p>
<a name="image-transformations"></a>
<h3 id="image-transformations">Image Transformations</h3>
<p>QImage supports a number of functions for creating a new image that is a transformed version of the original: The <a href="qimage.html#createAlphaMask">createAlphaMask</a>() function builds and returns a 1-bpp mask from the alpha buffer in this image, and the <a href="qimage.html#createHeuristicMask">createHeuristicMask</a>() function creates and returns a 1-bpp heuristic mask for this image. The latter function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges.</p>
<p>The <a href="qimage.html#mirrored">mirrored</a>() function returns a mirror of the image in the desired direction, the <a href="qimage.html#scaled">scaled</a>() returns a copy of the image scaled to a rectangle of the desired measures, and the <a href="qimage.html#rgbSwapped">rgbSwapped</a>() function constructs a BGR image from a RGB image.</p>
<p>The <a href="qimage.html#scaledToWidth">scaledToWidth</a>() and <a href="qimage.html#scaledToHeight">scaledToHeight</a>() functions return scaled copies of the image.</p>
<p>The <a href="qimage.html#transformed">transformed</a>() function returns a copy of the image that is transformed with the given transformation matrix and transformation mode: Internally, the transformation matrix is adjusted to compensate for unwanted translation, i.e&#x2e; <a href="qimage.html#transformed">transformed</a>() returns the smallest image containing all transformed points of the original image. The static <a href="qimage.html#trueMatrix">trueMatrix</a>() function returns the actual matrix used for transforming the image.</p>
<p>There are also functions for changing attributes of an image in-place:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Function</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><a href="qimage.html#setDotsPerMeterX">setDotsPerMeterX</a>()</td><td >Defines the aspect ratio by setting the number of pixels that fit horizontally in a physical meter.</td></tr>
<tr valign="top" class="even"><td ><a href="qimage.html#setDotsPerMeterY">setDotsPerMeterY</a>()</td><td >Defines the aspect ratio by setting the number of pixels that fit vertically in a physical meter.</td></tr>
<tr valign="top" class="odd"><td ><a href="qimage.html#fill">fill</a>()</td><td >Fills the entire image with the given pixel value.</td></tr>
<tr valign="top" class="even"><td ><a href="qimage.html#invertPixels">invertPixels</a>()</td><td >Inverts all pixel values in the image using the given <a href="qimage.html#InvertMode-enum">InvertMode</a> value.</td></tr>
<tr valign="top" class="odd"><td ><a href="qimage.html#setColorTable">setColorTable</a>()</td><td >Sets the color table used to translate color indexes. Only monochrome and 8-bit formats.</td></tr>
<tr valign="top" class="even"><td ><a href="qimage.html#setColorCount">setColorCount</a>()</td><td >Resizes the color table. Only monochrome and 8-bit formats.</td></tr>
</table></div>
</div>
<p><b>See also </b><a href="qimagereader.html">QImageReader</a>, <a href="qimagewriter.html">QImageWriter</a>, <a href="qpixmap.html">QPixmap</a>, <a href="../qtsvg/qsvgrenderer.html">QSvgRenderer</a>, <a href="../qtwidgets/qtwidgets-painting-imagecomposition-example.html">Image Composition Example</a>, <a href="../qtwidgets/qtwidgets-widgets-imageviewer-example.html">Image Viewer Example</a>, <a href="../qtwidgets/qtwidgets-widgets-scribble-example.html">Scribble Example</a>, and <a href="../qtwidgets/qtwidgets-itemviews-pixelator-example.html">Pixelator Example</a>.</p>
<!-- @@@QImage -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$Format$$$Format_Invalid$$$Format_Mono$$$Format_MonoLSB$$$Format_Indexed8$$$Format_RGB32$$$Format_ARGB32$$$Format_ARGB32_Premultiplied$$$Format_RGB16$$$Format_ARGB8565_Premultiplied$$$Format_RGB666$$$Format_ARGB6666_Premultiplied$$$Format_RGB555$$$Format_ARGB8555_Premultiplied$$$Format_RGB888$$$Format_RGB444$$$Format_ARGB4444_Premultiplied$$$Format_RGBX8888$$$Format_RGBA8888$$$Format_RGBA8888_Premultiplied$$$Format_BGR30$$$Format_A2BGR30_Premultiplied$$$Format_RGB30$$$Format_A2RGB30_Premultiplied$$$Format_Alpha8$$$Format_Grayscale8$$$Format_RGBX64$$$Format_RGBA64$$$Format_RGBA64_Premultiplied$$$Format_Grayscale16$$$Format_BGR888 -->
<h3 class="fn" id="Format-enum"><a name="Format-enum"></a>enum QImage::<span class="name">Format</span></h3>
<p>The following image formats are available in Qt. See the notes after the table.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QImage::Format_Invalid</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">The image is invalid.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_Mono</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">The image is stored using 1-bit per pixel. Bytes are packed with the most significant bit (MSB) first.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_MonoLSB</code></td><td class="topAlign tblval"><code>2</code></td><td class="topAlign">The image is stored using 1-bit per pixel. Bytes are packed with the less significant bit (LSB) first.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_Indexed8</code></td><td class="topAlign tblval"><code>3</code></td><td class="topAlign">The image is stored using 8-bit indexes into a colormap.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGB32</code></td><td class="topAlign tblval"><code>4</code></td><td class="topAlign">The image is stored using a 32-bit RGB format (0xffRRGGBB).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_ARGB32</code></td><td class="topAlign tblval"><code>5</code></td><td class="topAlign">The image is stored using a 32-bit ARGB format (0xAARRGGBB).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_ARGB32_Premultiplied</code></td><td class="topAlign tblval"><code>6</code></td><td class="topAlign">The image is stored using a premultiplied 32-bit ARGB format (0xAARRGGBB), i.e&#x2e; the red, green, and blue channels are multiplied by the alpha component divided by 255. (If RR, GG, or BB has a higher value than the alpha channel, the results are undefined.) Certain operations (such as image composition using alpha blending) are faster using premultiplied ARGB32 than with plain ARGB32.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGB16</code></td><td class="topAlign tblval"><code>7</code></td><td class="topAlign">The image is stored using a 16-bit RGB format (5-6-5).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_ARGB8565_Premultiplied</code></td><td class="topAlign tblval"><code>8</code></td><td class="topAlign">The image is stored using a premultiplied 24-bit ARGB format (8-5-6-5).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGB666</code></td><td class="topAlign tblval"><code>9</code></td><td class="topAlign">The image is stored using a 24-bit RGB format (6-6-6). The unused most significant bits is always zero.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_ARGB6666_Premultiplied</code></td><td class="topAlign tblval"><code>10</code></td><td class="topAlign">The image is stored using a premultiplied 24-bit ARGB format (6-6-6-6).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGB555</code></td><td class="topAlign tblval"><code>11</code></td><td class="topAlign">The image is stored using a 16-bit RGB format (5-5-5). The unused most significant bit is always zero.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_ARGB8555_Premultiplied</code></td><td class="topAlign tblval"><code>12</code></td><td class="topAlign">The image is stored using a premultiplied 24-bit ARGB format (8-5-5-5).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGB888</code></td><td class="topAlign tblval"><code>13</code></td><td class="topAlign">The image is stored using a 24-bit RGB format (8-8-8).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGB444</code></td><td class="topAlign tblval"><code>14</code></td><td class="topAlign">The image is stored using a 16-bit RGB format (4-4-4). The unused bits are always zero.</td></tr>
<tr><td class="topAlign"><code>QImage::Format_ARGB4444_Premultiplied</code></td><td class="topAlign tblval"><code>15</code></td><td class="topAlign">The image is stored using a premultiplied 16-bit ARGB format (4-4-4-4).</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGBX8888</code></td><td class="topAlign tblval"><code>16</code></td><td class="topAlign">The image is stored using a 32-bit byte-ordered RGB(x) format (8-8-8-8). This is the same as the Format_RGBA8888 except alpha must always be 255. (added in Qt 5.2)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGBA8888</code></td><td class="topAlign tblval"><code>17</code></td><td class="topAlign">The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8). Unlike ARGB32 this is a byte-ordered format, which means the 32bit encoding differs between big endian and little endian architectures, being respectively (0xRRGGBBAA) and (0xAABBGGRR). The order of the colors is the same on any architecture if read as bytes 0xRR,0xGG,0xBB,0xAA. (added in Qt 5.2)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGBA8888_Premultiplied</code></td><td class="topAlign tblval"><code>18</code></td><td class="topAlign">The image is stored using a premultiplied 32-bit byte-ordered RGBA format (8-8-8-8). (added in Qt 5.2)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_BGR30</code></td><td class="topAlign tblval"><code>19</code></td><td class="topAlign">The image is stored using a 32-bit BGR format (x-10-10-10). (added in Qt 5.4)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_A2BGR30_Premultiplied</code></td><td class="topAlign tblval"><code>20</code></td><td class="topAlign">The image is stored using a 32-bit premultiplied ABGR format (2-10-10-10). (added in Qt 5.4)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGB30</code></td><td class="topAlign tblval"><code>21</code></td><td class="topAlign">The image is stored using a 32-bit RGB format (x-10-10-10). (added in Qt 5.4)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_A2RGB30_Premultiplied</code></td><td class="topAlign tblval"><code>22</code></td><td class="topAlign">The image is stored using a 32-bit premultiplied ARGB format (2-10-10-10). (added in Qt 5.4)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_Alpha8</code></td><td class="topAlign tblval"><code>23</code></td><td class="topAlign">The image is stored using an 8-bit alpha only format. (added in Qt 5.5)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_Grayscale8</code></td><td class="topAlign tblval"><code>24</code></td><td class="topAlign">The image is stored using an 8-bit grayscale format. (added in Qt 5.5)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_Grayscale16</code></td><td class="topAlign tblval"><code>28</code></td><td class="topAlign">The image is stored using an 16-bit grayscale format. (added in Qt 5.13)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGBX64</code></td><td class="topAlign tblval"><code>25</code></td><td class="topAlign">The image is stored using a 64-bit halfword-ordered RGB(x) format (16-16-16-16). This is the same as the Format_RGBA64 except alpha must always be 65535. (added in Qt 5.12)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGBA64</code></td><td class="topAlign tblval"><code>26</code></td><td class="topAlign">The image is stored using a 64-bit halfword-ordered RGBA format (16-16-16-16). (added in Qt 5.12)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_RGBA64_Premultiplied</code></td><td class="topAlign tblval"><code>27</code></td><td class="topAlign">The image is stored using a premultiplied 64-bit halfword-ordered RGBA format (16-16-16-16). (added in Qt 5.12)</td></tr>
<tr><td class="topAlign"><code>QImage::Format_BGR888</code></td><td class="topAlign tblval"><code>29</code></td><td class="topAlign">The image is stored using a 24-bit BGR format. (added in Qt 5.14)</td></tr>
</table></div>
<p><b>Note: </b>Drawing into a <a href="qimage.html">QImage</a> with QImage::Format_Indexed8 is not supported.</p><p><b>Note: </b>Avoid most rendering directly to most of these formats using <a href="qpainter.html">QPainter</a>. Rendering is best optimized to the <code>Format_RGB32</code> and <code>Format_ARGB32_Premultiplied</code> formats, and secondarily for rendering to the <code>Format_RGB16</code>, <code>Format_RGBX8888</code>, <code>Format_RGBA8888_Premultiplied</code>, <code>Format_RGBX64</code> and <code>Format_RGBA64_Premultiplied</code> formats</p><p><b>See also </b><a href="qimage.html#format">format</a>() and <a href="qimage.html#convertToFormat">convertToFormat</a>().</p>
<!-- @@@Format -->
<!-- $$$InvertMode$$$InvertRgb$$$InvertRgba -->
<h3 class="fn" id="InvertMode-enum"><a name="InvertMode-enum"></a>enum QImage::<span class="name">InvertMode</span></h3>
<p>This enum type is used to describe how pixel values should be inverted in the <a href="qimage.html#invertPixels">invertPixels</a>() function.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QImage::InvertRgb</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">Invert only the RGB values and leave the alpha channel unchanged.</td></tr>
<tr><td class="topAlign"><code>QImage::InvertRgba</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">Invert all channels, including the alpha channel.</td></tr>
</table></div>
<p><b>See also </b><a href="qimage.html#invertPixels">invertPixels</a>().</p>
<!-- @@@InvertMode -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$ -->
<div class="fngroup">
<h3 class="fn fngroupitem" id="rgbSwapped-1"><a name="rgbSwapped-1"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;&amp;QImage::<span class="name">rgbSwapped</span>() &&</h3><h3 class="fn fngroupitem" id="rgbSwapped"><a name="rgbSwapped"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">rgbSwapped</span>() const &</h3></div>
<p>Returns a <a href="qimage.html">QImage</a> in which the values of the red and blue components of all pixels have been swapped, effectively converting an RGB image to an BGR image.</p>
<p>The original <a href="qimage.html">QImage</a> is not changed.</p>
<p><b>See also </b><a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@ -->
<!-- $$$ -->
<div class="fngroup">
<h3 class="fn fngroupitem" id="mirrored-1"><a name="mirrored-1"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;&amp;QImage::<span class="name">mirrored</span>(<span class="type">bool</span> <i>horizontal</i> = ..., <span class="type">bool</span> <i>vertical</i> = ...) &&</h3><h3 class="fn fngroupitem" id="mirrored"><a name="mirrored"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">mirrored</span>(<span class="type">bool</span> <i>horizontal</i> = ..., <span class="type">bool</span> <i>vertical</i> = ...) const &</h3></div>
<p>Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether <i>horizontal</i> and <i>vertical</i> are set to true or false.</p>
<p>Note that the original image is not changed.</p>
<p><b>See also </b><a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@ -->
<!-- $$$ -->
<div class="fngroup">
<h3 class="fn fngroupitem" id="convertToFormat-1"><a name="convertToFormat-1"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">convertToFormat</span>(<span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, <span class="type"><a href="../qtcore/qt.html#ImageConversionFlag-enum">Qt::ImageConversionFlags</a></span> <i>flags</i> = Qt::AutoColor) &&</h3><h3 class="fn fngroupitem" id="convertToFormat"><a name="convertToFormat"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">convertToFormat</span>(<span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, <span class="type"><a href="../qtcore/qt.html#ImageConversionFlag-enum">Qt::ImageConversionFlags</a></span> <i>flags</i> = Qt::AutoColor) const &</h3></div>
<p>Returns a copy of the image in the given <i>format</i>.</p>
<p>The specified image conversion <i>flags</i> control how the image data is handled during the conversion process.</p>
<p><b>See also </b><a href="qimage.html#image-formats">Image Formats</a>.</p>
<!-- @@@ -->
<!-- $$$QImage$$$QImageQImage&& -->
<h3 class="fn" id="QImage-10"><a name="QImage-10"></a>QImage::<span class="name">QImage</span>(<span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;&amp;<i>other</i>)</h3>
<p>Move-constructs a QImage instance, making it point at the same object that <i>other</i> was pointing to.</p>
<p>This function was introduced in Qt 5.2.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageconstQImage& -->
<h3 class="fn" id="QImage-9"><a name="QImage-9"></a>QImage::<span class="name">QImage</span>(const <span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;<i>image</i>)</h3>
<p>Constructs a shallow copy of the given <i>image</i>.</p>
<p>For more information about shallow copies, see the <a href="../qtcore/implicit-sharing.html">Implicit Data Sharing</a> documentation.</p>
<p><b>See also </b><a href="qimage.html#copy">copy</a>().</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageconstQString&constchar* -->
<h3 class="fn" id="QImage-8"><a name="QImage-8"></a>QImage::<span class="name">QImage</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>fileName</i>, const <span class="type">char</span> *<i>format</i> = nullptr)</h3>
<p>Constructs an image and tries to load the image from the file with the given <i>fileName</i>.</p>
<p>The loader attempts to read the image using the specified <i>format</i>. If the <i>format</i> is not specified (which is the default), it is auto-detected based on the file's suffix and header. For details, see {<a href="qimagereader.html#setAutoDetectImageFormat">QImageReader::setAutoDetectImageFormat</a>()}{<a href="qimagereader.html">QImageReader</a>}.</p>
<p>If the loading of the image failed, this object is a null image.</p>
<p>The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the <a href="../qtcore/resources.html">Resource System</a> overview for details on how to embed images and other resource files in the application's executable.</p>
<p><b>See also </b><a href="qimage.html#isNull">isNull</a>() and <a href="qimage.html#reading-and-writing-image-files">Reading and Writing Image Files</a>.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageconstchar*const[] -->
<h3 class="fn" id="QImage-7"><a name="QImage-7"></a>QImage::<span class="name">QImage</span>(const <span class="type">char</span> *const [] <i>xpm</i>)</h3>
<p>Constructs an image from the given <i>xpm</i> image.</p>
<p>Make sure that the image is a valid XPM image. Errors are silently ignored.</p>
<p>Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:</p>
<pre class="cpp">

  <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span> <span class="keyword">const</span> start_xpm<span class="operator">[</span><span class="operator">]</span> <span class="operator">=</span> {
      <span class="string">&quot;16 15 8 1&quot;</span><span class="operator">,</span>
      <span class="string">&quot;a c #cec6bd&quot;</span><span class="operator">,</span>
  <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>

</pre>
<p>The extra <code>const</code> makes the entire definition read-only, which is slightly more efficient (e.g&#x2e;, when the code is in a shared library) and able to be stored in ROM with the application.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageconstuchar*intintintQImage::FormatQImageCleanupFunctionvoid* -->
<h3 class="fn" id="QImage-6"><a name="QImage-6"></a>QImage::<span class="name">QImage</span>(const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *<i>data</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>, <span class="type">int</span> <i>bytesPerLine</i>, <span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, <span class="type"><a href="qimage.html#QImageCleanupFunction-typedef">QImageCleanupFunction</a></span> <i>cleanupFunction</i> = nullptr, <span class="type">void</span> *<i>cleanupInfo</i> = nullptr)</h3>
<p>Constructs an image with the given <i>width</i>, <i>height</i> and <i>format</i>, that uses an existing memory buffer, <i>data</i>. The <i>width</i> and <i>height</i> must be specified in pixels. <i>bytesPerLine</i> specifies the number of bytes per line (stride).</p>
<p>The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer <i>cleanupFunction</i> along with an extra pointer <i>cleanupInfo</i> that will be called when the last copy is destroyed.</p>
<p>If <i>format</i> is an indexed color format, the image color table is initially empty and must be sufficiently expanded with <a href="qimage.html#setColorCount">setColorCount</a>() or <a href="qimage.html#setColorTable">setColorTable</a>() before the image is used.</p>
<p>Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, calling <a href="qimage.html#bits">QImage::bits</a>() will return a deep copy of the image, rather than the buffer passed to the constructor. This allows for the efficiency of constructing a QImage from raw data, without the possibility of the raw data being changed.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageuchar*intintintQImage::FormatQImageCleanupFunctionvoid* -->
<h3 class="fn" id="QImage-5"><a name="QImage-5"></a>QImage::<span class="name">QImage</span>(<span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *<i>data</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>, <span class="type">int</span> <i>bytesPerLine</i>, <span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, <span class="type"><a href="qimage.html#QImageCleanupFunction-typedef">QImageCleanupFunction</a></span> <i>cleanupFunction</i> = nullptr, <span class="type">void</span> *<i>cleanupInfo</i> = nullptr)</h3>
<p>Constructs an image with the given <i>width</i>, <i>height</i> and <i>format</i>, that uses an existing memory buffer, <i>data</i>. The <i>width</i> and <i>height</i> must be specified in pixels. <i>bytesPerLine</i> specifies the number of bytes per line (stride).</p>
<p>The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer <i>cleanupFunction</i> along with an extra pointer <i>cleanupInfo</i> that will be called when the last copy is destroyed.</p>
<p>If <i>format</i> is an indexed color format, the image color table is initially empty and must be sufficiently expanded with <a href="qimage.html#setColorCount">setColorCount</a>() or <a href="qimage.html#setColorTable">setColorTable</a>() before the image is used.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageconstuchar*intintQImage::FormatQImageCleanupFunctionvoid* -->
<h3 class="fn" id="QImage-4"><a name="QImage-4"></a>QImage::<span class="name">QImage</span>(const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *<i>data</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>, <span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, <span class="type"><a href="qimage.html#QImageCleanupFunction-typedef">QImageCleanupFunction</a></span> <i>cleanupFunction</i> = nullptr, <span class="type">void</span> *<i>cleanupInfo</i> = nullptr)</h3>
<p>Constructs an image with the given <i>width</i>, <i>height</i> and <i>format</i>, that uses an existing read-only memory buffer, <i>data</i>. The <i>width</i> and <i>height</i> must be specified in pixels, <i>data</i> must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.</p>
<p>The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer <i>cleanupFunction</i> along with an extra pointer <i>cleanupInfo</i> that will be called when the last copy is destroyed.</p>
<p>If <i>format</i> is an indexed color format, the image color table is initially empty and must be sufficiently expanded with <a href="qimage.html#setColorCount">setColorCount</a>() or <a href="qimage.html#setColorTable">setColorTable</a>() before the image is used.</p>
<p>Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, calling <a href="qimage.html#bits">QImage::bits</a>() will return a deep copy of the image, rather than the buffer passed to the constructor. This allows for the efficiency of constructing a QImage from raw data, without the possibility of the raw data being changed.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageuchar*intintQImage::FormatQImageCleanupFunctionvoid* -->
<h3 class="fn" id="QImage-3"><a name="QImage-3"></a>QImage::<span class="name">QImage</span>(<span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *<i>data</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>, <span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, <span class="type"><a href="qimage.html#QImageCleanupFunction-typedef">QImageCleanupFunction</a></span> <i>cleanupFunction</i> = nullptr, <span class="type">void</span> *<i>cleanupInfo</i> = nullptr)</h3>
<p>Constructs an image with the given <i>width</i>, <i>height</i> and <i>format</i>, that uses an existing memory buffer, <i>data</i>. The <i>width</i> and <i>height</i> must be specified in pixels, <i>data</i> must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.</p>
<p>The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer <i>cleanupFunction</i> along with an extra pointer <i>cleanupInfo</i> that will be called when the last copy is destroyed.</p>
<p>If <i>format</i> is an indexed color format, the image color table is initially empty and must be sufficiently expanded with <a href="qimage.html#setColorCount">setColorCount</a>() or <a href="qimage.html#setColorTable">setColorTable</a>() before the image is used.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageintintQImage::Format -->
<h3 class="fn" id="QImage-2"><a name="QImage-2"></a>QImage::<span class="name">QImage</span>(<span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>, <span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>)</h3>
<p>Constructs an image with the given <i>width</i>, <i>height</i> and <i>format</i>.</p>
<p>A <a href="qimage.html#isNull">null</a> image will be returned if memory cannot be allocated.</p>
<p><b>Warning:</b> This will create a QImage with uninitialized data. Call <a href="qimage.html#fill">fill</a>() to fill the image with an appropriate pixel value before drawing onto it with <a href="qpainter.html">QPainter</a>.</p>
<!-- @@@QImage -->
<!-- $$$QImage$$$QImageconstQSize&QImage::Format -->
<h3 class="fn" id="QImage-1"><a name="QImage-1"></a>QImage::<span class="name">QImage</span>(const <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> &amp;<i>size</i>, <span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>)</h3>
<p>Constructs an image with the given <i>size</i> and <i>format</i>.</p>
<p>A <a href="qimage.html#isNull">null</a> image is returned if memory cannot be allocated.</p>
<p><b>Warning:</b> This will create a QImage with uninitialized data. Call <a href="qimage.html#fill">fill</a>() to fill the image with an appropriate pixel value before drawing onto it with <a href="qpainter.html">QPainter</a>.</p>
<!-- @@@QImage -->
<!-- $$$QImage[overload1]$$$QImage -->
<h3 class="fn" id="QImage"><a name="QImage"></a>QImage::<span class="name">QImage</span>()</h3>
<p>Constructs a null image.</p>
<p><b>See also </b><a href="qimage.html#isNull">isNull</a>().</p>
<!-- @@@QImage -->
<!-- $$$operator=$$$operator=QImage&& -->
<h3 class="fn" id="operator-eq-1"><a name="operator-eq-1"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;QImage::<span class="name">operator=</span>(<span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;&amp;<i>other</i>)</h3>
<p>Move-assigns <i>other</i> to this <a href="qimage.html">QImage</a> instance.</p>
<p>This function was introduced in Qt 5.2.</p>
<!-- @@@operator= -->
<!-- $$$operator=[overload1]$$$operator=constQImage& -->
<h3 class="fn" id="operator-eq"><a name="operator-eq"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;QImage::<span class="name">operator=</span>(const <span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;<i>image</i>)</h3>
<p>Assigns a shallow copy of the given <i>image</i> to this image and returns a reference to this image.</p>
<p>For more information about shallow copies, see the <a href="../qtcore/implicit-sharing.html">Implicit Data Sharing</a> documentation.</p>
<p><b>See also </b><a href="qimage.html#copy">copy</a>() and <a href="qimage.html#QImage">QImage</a>().</p>
<!-- @@@operator= -->
<!-- $$$~QImage[overload1]$$$~QImage -->
<h3 class="fn" id="dtor.QImage"><a name="dtor.QImage"></a><code>[virtual] </code>QImage::<span class="name">~QImage</span>()</h3>
<p>Destroys the image and cleans up.</p>
<!-- @@@~QImage -->
<!-- $$$allGray[overload1]$$$allGray -->
<h3 class="fn" id="allGray"><a name="allGray"></a><span class="type">bool</span> QImage::<span class="name">allGray</span>() const</h3>
<p>Returns <code>true</code> if all the colors in the image are shades of gray (i.e&#x2e; their red, green and blue components are equal); otherwise false.</p>
<p>Note that this function is slow for images without color table.</p>
<p><b>See also </b><a href="qimage.html#isGrayscale">isGrayscale</a>().</p>
<!-- @@@allGray -->
<!-- $$$applyColorTransform[overload1]$$$applyColorTransformconstQColorTransform& -->
<h3 class="fn" id="applyColorTransform"><a name="applyColorTransform"></a><span class="type">void</span> QImage::<span class="name">applyColorTransform</span>(const <span class="type"><a href="qcolortransform.html">QColorTransform</a></span> &amp;<i>transform</i>)</h3>
<p>Applies the color transformation <i>transform</i> to all pixels in the image.</p>
<p>This function was introduced in Qt 5.14.</p>
<!-- @@@applyColorTransform -->
<!-- $$$bitPlaneCount[overload1]$$$bitPlaneCount -->
<h3 class="fn" id="bitPlaneCount"><a name="bitPlaneCount"></a><span class="type">int</span> QImage::<span class="name">bitPlaneCount</span>() const</h3>
<p>Returns the number of bit planes in the image.</p>
<p>The number of bit planes is the number of bits of color and transparency information for each pixel. This is different from (i.e&#x2e; smaller than) the depth when the image format contains unused bits.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also </b><a href="qimage.html#depth">depth</a>(), <a href="qimage.html#format">format</a>(), and <a href="qimage.html#image-formats">Image Formats</a>.</p>
<!-- @@@bitPlaneCount -->
<!-- $$$bits[overload1]$$$bits -->
<h3 class="fn" id="bits"><a name="bits"></a><span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *QImage::<span class="name">bits</span>()</h3>
<p>Returns a pointer to the first pixel data. This is equivalent to <a href="qimage.html#scanLine">scanLine</a>(0).</p>
<p>Note that <a href="qimage.html">QImage</a> uses <a href="../qtcore/implicit-sharing.html">implicit data sharing</a>. This function performs a deep copy of the shared pixel data, thus ensuring that this <a href="qimage.html">QImage</a> is the only one using the current return value.</p>
<p><b>See also </b><a href="qimage.html#scanLine">scanLine</a>(), <a href="qimage.html#sizeInBytes">sizeInBytes</a>(), and <a href="qimage.html#constBits">constBits</a>().</p>
<!-- @@@bits -->
<!-- $$$bits$$$bits -->
<h3 class="fn" id="bits-1"><a name="bits-1"></a>const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *QImage::<span class="name">bits</span>() const</h3>
<p>This is an overloaded function.</p>
<p>Note that <a href="qimage.html">QImage</a> uses <a href="../qtcore/implicit-sharing.html">implicit data sharing</a>, but this function does <i>not</i> perform a deep copy of the shared pixel data, because the returned data is const.</p>
<!-- @@@bits -->
<!-- $$$bytesPerLine[overload1]$$$bytesPerLine -->
<h3 class="fn" id="bytesPerLine"><a name="bytesPerLine"></a><span class="type">int</span> QImage::<span class="name">bytesPerLine</span>() const</h3>
<p>Returns the number of bytes per image scanline.</p>
<p>This is equivalent to <a href="qimage.html#sizeInBytes">sizeInBytes</a>() / <a href="qimage.html#height">height</a>() if <a href="qimage.html#height">height</a>() is non-zero.</p>
<p><b>See also </b><a href="qimage.html#scanLine">scanLine</a>().</p>
<!-- @@@bytesPerLine -->
<!-- $$$cacheKey[overload1]$$$cacheKey -->
<h3 class="fn" id="cacheKey"><a name="cacheKey"></a><span class="type"><a href="../qtcore/qtglobal.html#qint64-typedef">qint64</a></span> QImage::<span class="name">cacheKey</span>() const</h3>
<p>Returns a number that identifies the contents of this <a href="qimage.html">QImage</a> object. Distinct <a href="qimage.html">QImage</a> objects can only have the same key if they refer to the same contents.</p>
<p>The key will change when the image is altered.</p>
<!-- @@@cacheKey -->
<!-- $$$color[overload1]$$$colorint -->
<h3 class="fn" id="color"><a name="color"></a><span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span> QImage::<span class="name">color</span>(<span class="type">int</span> <i>i</i>) const</h3>
<p>Returns the color in the color table at index <i>i</i>. The first color is at index 0.</p>
<p>The colors in an image's color table are specified as ARGB quadruplets (<a href="qcolor.html#QRgb-typedef">QRgb</a>). Use the <a href="qcolor.html#qAlpha">qAlpha</a>(), <a href="qcolor.html#qRed">qRed</a>(), <a href="qcolor.html#qGreen">qGreen</a>(), and <a href="qcolor.html#qBlue">qBlue</a>() functions to get the color value components.</p>
<p><b>See also </b><a href="qimage.html#setColor">setColor</a>(), <a href="qimage.html#pixelIndex">pixelIndex</a>(), and <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>.</p>
<!-- @@@color -->
<!-- $$$colorCount[overload1]$$$colorCount -->
<h3 class="fn" id="colorCount"><a name="colorCount"></a><span class="type">int</span> QImage::<span class="name">colorCount</span>() const</h3>
<p>Returns the size of the color table for the image.</p>
<p>Notice that colorCount() returns 0 for 32-bpp images because these images do not use color tables, but instead encode pixel values as ARGB quadruplets.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also </b><a href="qimage.html#setColorCount">setColorCount</a>() and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@colorCount -->
<!-- $$$colorSpace[overload1]$$$colorSpace -->
<h3 class="fn" id="colorSpace"><a name="colorSpace"></a><span class="type"><a href="qcolorspace.html">QColorSpace</a></span> QImage::<span class="name">colorSpace</span>() const</h3>
<p>Returns the color space of the image if a color space is defined.</p>
<p>This function was introduced in Qt 5.14.</p>
<p><b>See also </b><a href="qimage.html#setColorSpace">setColorSpace</a>().</p>
<!-- @@@colorSpace -->
<!-- $$$colorTable[overload1]$$$colorTable -->
<h3 class="fn" id="colorTable"><a name="colorTable"></a><span class="type"><a href="../qtcore/qvector.html">QVector</a></span>&lt;<span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span>&gt; QImage::<span class="name">colorTable</span>() const</h3>
<p>Returns a list of the colors contained in the image's color table, or an empty list if the image does not have a color table</p>
<p><b>See also </b><a href="qimage.html#setColorTable">setColorTable</a>(), <a href="qimage.html#colorCount">colorCount</a>(), and <a href="qimage.html#color">color</a>().</p>
<!-- @@@colorTable -->
<!-- $$$constBits[overload1]$$$constBits -->
<h3 class="fn" id="constBits"><a name="constBits"></a>const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *QImage::<span class="name">constBits</span>() const</h3>
<p>Returns a pointer to the first pixel data.</p>
<p>Note that <a href="qimage.html">QImage</a> uses <a href="../qtcore/implicit-sharing.html">implicit data sharing</a>, but this function does <i>not</i> perform a deep copy of the shared pixel data, because the returned data is const.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also </b><a href="qimage.html#bits">bits</a>() and <a href="qimage.html#constScanLine">constScanLine</a>().</p>
<!-- @@@constBits -->
<!-- $$$constScanLine[overload1]$$$constScanLineint -->
<h3 class="fn" id="constScanLine"><a name="constScanLine"></a>const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *QImage::<span class="name">constScanLine</span>(<span class="type">int</span> <i>i</i>) const</h3>
<p>Returns a pointer to the pixel data at the scanline with index <i>i</i>. The first scanline is at index 0.</p>
<p>The scanline data is as minimum 32-bit aligned. For 64-bit formats it follows the native alignment of 64-bit integers (64-bit for most platforms, but notably 32-bit on i386).</p>
<p>Note that <a href="qimage.html">QImage</a> uses <a href="../qtcore/implicit-sharing.html">implicit data sharing</a>, but this function does <i>not</i> perform a deep copy of the shared pixel data, because the returned data is const.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also </b><a href="qimage.html#scanLine">scanLine</a>() and <a href="qimage.html#constBits">constBits</a>().</p>
<!-- @@@constScanLine -->
<!-- $$$convertTo[overload1]$$$convertToQImage::FormatQt::ImageConversionFlags -->
<h3 class="fn" id="convertTo"><a name="convertTo"></a><span class="type">void</span> QImage::<span class="name">convertTo</span>(<span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, <span class="type"><a href="../qtcore/qt.html#ImageConversionFlag-enum">Qt::ImageConversionFlags</a></span> <i>flags</i> = Qt::AutoColor)</h3>
<p>Detach and convert the image to the given <i>format</i> in place.</p>
<p>The specified image conversion <i>flags</i> control how the image data is handled during the conversion process.</p>
<p>This function was introduced in Qt 5.13.</p>
<p><b>See also </b><a href="qimage.html#convertToFormat">convertToFormat</a>().</p>
<!-- @@@convertTo -->
<!-- $$$convertToColorSpace[overload1]$$$convertToColorSpaceconstQColorSpace& -->
<h3 class="fn" id="convertToColorSpace"><a name="convertToColorSpace"></a><span class="type">void</span> QImage::<span class="name">convertToColorSpace</span>(const <span class="type"><a href="qcolorspace.html">QColorSpace</a></span> &amp;<i>colorSpace</i>)</h3>
<p>Converts the image to <i>colorSpace</i>.</p>
<p>If the image has no valid color space, the method does nothing.</p>
<p>This function was introduced in Qt 5.14.</p>
<p><b>See also </b><a href="qimage.html#convertedToColorSpace">convertedToColorSpace</a>() and <a href="qimage.html#setColorSpace">setColorSpace</a>().</p>
<!-- @@@convertToColorSpace -->
<!-- $$$convertToFormat$$$convertToFormatQImage::FormatconstQVector<QRgb>&Qt::ImageConversionFlags -->
<h3 class="fn" id="convertToFormat-2"><a name="convertToFormat-2"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">convertToFormat</span>(<span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>, const <span class="type"><a href="../qtcore/qvector.html">QVector</a></span>&lt;<span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span>&gt; &amp;<i>colorTable</i>, <span class="type"><a href="../qtcore/qt.html#ImageConversionFlag-enum">Qt::ImageConversionFlags</a></span> <i>flags</i> = Qt::AutoColor) const</h3>
<p>This is an overloaded function.</p>
<p>Returns a copy of the image converted to the given <i>format</i>, using the specified <i>colorTable</i>.</p>
<p>Conversion from RGB formats to indexed formats is a slow operation and will use a straightforward nearest color approach, with no dithering.</p>
<!-- @@@convertToFormat -->
<!-- $$$convertedToColorSpace[overload1]$$$convertedToColorSpaceconstQColorSpace& -->
<h3 class="fn" id="convertedToColorSpace"><a name="convertedToColorSpace"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">convertedToColorSpace</span>(const <span class="type"><a href="qcolorspace.html">QColorSpace</a></span> &amp;<i>colorSpace</i>) const</h3>
<p>Returns the image converted to <i>colorSpace</i>.</p>
<p>If the image has no valid color space, a null <a href="qimage.html">QImage</a> is returned.</p>
<p>This function was introduced in Qt 5.14.</p>
<p><b>See also </b><a href="qimage.html#convertToColorSpace">convertToColorSpace</a>().</p>
<!-- @@@convertedToColorSpace -->
<!-- $$$copy[overload1]$$$copyconstQRect& -->
<h3 class="fn" id="copy"><a name="copy"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">copy</span>(const <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> &amp;<i>rectangle</i> = QRect()) const</h3>
<p>Returns a sub-area of the image as a new image.</p>
<p>The returned image is copied from the position (<i>rectangle</i>.x(), <i>rectangle</i>.y()) in this image, and will always have the size of the given <i>rectangle</i>.</p>
<p>In areas beyond this image, pixels are set to 0. For 32-bit RGB images, this means black; for 32-bit ARGB images, this means transparent black; for 8-bit images, this means the color with index 0 in the color table which can be anything; for 1-bit images, this means <a href="../qtcore/qt.html#GlobalColor-enum">Qt::color0</a>.</p>
<p>If the given <i>rectangle</i> is a null rectangle the entire image is copied.</p>
<p><b>See also </b><a href="qimage.html#QImage">QImage</a>().</p>
<!-- @@@copy -->
<!-- $$$copy$$$copyintintintint -->
<h3 class="fn" id="copy-1"><a name="copy-1"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">copy</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>) const</h3>
<p>This is an overloaded function.</p>
<p>The returned image is copied from the position (<i>x</i>, <i>y</i>) in this image, and will always have the given <i>width</i> and <i>height</i>. In areas beyond this image, pixels are set to 0.</p>
<!-- @@@copy -->
<!-- $$$createAlphaMask[overload1]$$$createAlphaMaskQt::ImageConversionFlags -->
<h3 class="fn" id="createAlphaMask"><a name="createAlphaMask"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">createAlphaMask</span>(<span class="type"><a href="../qtcore/qt.html#ImageConversionFlag-enum">Qt::ImageConversionFlags</a></span> <i>flags</i> = Qt::AutoColor) const</h3>
<p>Builds and returns a 1-bpp mask from the alpha buffer in this image. Returns a null image if the image's format is <a href="qimage.html#Format-enum">QImage::Format_RGB32</a>.</p>
<p>The <i>flags</i> argument is a bitwise-OR of the <a href="../qtcore/qt.html#ImageConversionFlag-enum">Qt::ImageConversionFlags</a>, and controls the conversion process. Passing 0 for flags sets all the default options.</p>
<p>The returned image has little-endian bit order (i.e&#x2e; the image's format is <a href="qimage.html#Format-enum">QImage::Format_MonoLSB</a>), which you can convert to big-endian (<a href="qimage.html#Format-enum">QImage::Format_Mono</a>) using the <a href="qimage.html#convertToFormat">convertToFormat</a>() function.</p>
<p><b>See also </b><a href="qimage.html#createHeuristicMask">createHeuristicMask</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@createAlphaMask -->
<!-- $$$createHeuristicMask[overload1]$$$createHeuristicMaskbool -->
<h3 class="fn" id="createHeuristicMask"><a name="createHeuristicMask"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">createHeuristicMask</span>(<span class="type">bool</span> <i>clipTight</i> = true) const</h3>
<p>Creates and returns a 1-bpp heuristic mask for this image.</p>
<p>The function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges. The four corners vote for which color is to be masked away. In case of a draw (this generally means that this function is not applicable to the image), the result is arbitrary.</p>
<p>The returned image has little-endian bit order (i.e&#x2e; the image's format is <a href="qimage.html#Format-enum">QImage::Format_MonoLSB</a>), which you can convert to big-endian (<a href="qimage.html#Format-enum">QImage::Format_Mono</a>) using the <a href="qimage.html#convertToFormat">convertToFormat</a>() function.</p>
<p>If <i>clipTight</i> is true (the default) the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.</p>
<p>Note that this function disregards the alpha buffer.</p>
<p><b>See also </b><a href="qimage.html#createAlphaMask">createAlphaMask</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@createHeuristicMask -->
<!-- $$$createMaskFromColor[overload1]$$$createMaskFromColorQRgbQt::MaskMode -->
<h3 class="fn" id="createMaskFromColor"><a name="createMaskFromColor"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">createMaskFromColor</span>(<span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span> <i>color</i>, <span class="type"><a href="../qtcore/qt.html#MaskMode-enum">Qt::MaskMode</a></span> <i>mode</i> = Qt::MaskInColor) const</h3>
<p>Creates and returns a mask for this image based on the given <i>color</i> value. If the <i>mode</i> is MaskInColor (the default value), all pixels matching <i>color</i> will be opaque pixels in the mask. If <i>mode</i> is MaskOutColor, all pixels matching the given color will be transparent.</p>
<p><b>See also </b><a href="qimage.html#createAlphaMask">createAlphaMask</a>() and <a href="qimage.html#createHeuristicMask">createHeuristicMask</a>().</p>
<!-- @@@createMaskFromColor -->
<!-- $$$depth[overload1]$$$depth -->
<h3 class="fn" id="depth"><a name="depth"></a><span class="type">int</span> QImage::<span class="name">depth</span>() const</h3>
<p>Returns the depth of the image.</p>
<p>The image depth is the number of bits used to store a single pixel, also called bits per pixel (bpp).</p>
<p>The supported depths are 1, 8, 16, 24, 32 and 64.</p>
<p><b>See also </b><a href="qimage.html#bitPlaneCount">bitPlaneCount</a>(), <a href="qimage.html#convertToFormat">convertToFormat</a>(), <a href="qimage.html#image-formats">Image Formats</a>, and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@depth -->
<!-- $$$devicePixelRatio[overload1]$$$devicePixelRatio -->
<h3 class="fn" id="devicePixelRatio"><a name="devicePixelRatio"></a><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> QImage::<span class="name">devicePixelRatio</span>() const</h3>
<p>Returns the device pixel ratio for the image. This is the ratio between <i>device pixels</i> and <i>device independent pixels</i>.</p>
<p>Use this function when calculating layout geometry based on the image size: <a href="../qtcore/qsize.html">QSize</a> layoutSize = image.<a href="qimage.html#size">size</a>() / image.devicePixelRatio()</p>
<p>The default value is 1.0&#x2e;</p>
<p><b>See also </b><a href="qimage.html#setDevicePixelRatio">setDevicePixelRatio</a>() and <a href="qimagereader.html">QImageReader</a>.</p>
<!-- @@@devicePixelRatio -->
<!-- $$$dotsPerMeterX[overload1]$$$dotsPerMeterX -->
<h3 class="fn" id="dotsPerMeterX"><a name="dotsPerMeterX"></a><span class="type">int</span> QImage::<span class="name">dotsPerMeterX</span>() const</h3>
<p>Returns the number of pixels that fit horizontally in a physical meter. Together with <a href="qimage.html#dotsPerMeterY">dotsPerMeterY</a>(), this number defines the intended scale and aspect ratio of the image.</p>
<p><b>See also </b><a href="qimage.html#setDotsPerMeterX">setDotsPerMeterX</a>() and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@dotsPerMeterX -->
<!-- $$$dotsPerMeterY[overload1]$$$dotsPerMeterY -->
<h3 class="fn" id="dotsPerMeterY"><a name="dotsPerMeterY"></a><span class="type">int</span> QImage::<span class="name">dotsPerMeterY</span>() const</h3>
<p>Returns the number of pixels that fit vertically in a physical meter. Together with <a href="qimage.html#dotsPerMeterX">dotsPerMeterX</a>(), this number defines the intended scale and aspect ratio of the image.</p>
<p><b>See also </b><a href="qimage.html#setDotsPerMeterY">setDotsPerMeterY</a>() and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@dotsPerMeterY -->
<!-- $$$fill[overload1]$$$filluint -->
<h3 class="fn" id="fill"><a name="fill"></a><span class="type">void</span> QImage::<span class="name">fill</span>(<span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> <i>pixelValue</i>)</h3>
<p>Fills the entire image with the given <i>pixelValue</i>.</p>
<p>If the depth of this image is 1, only the lowest bit is used. If you say fill(0), fill(2), etc., the image is filled with 0s. If you say fill(1), fill(3), etc., the image is filled with 1s. If the depth is 8, the lowest 8 bits are used and if the depth is 16 the lowest 16 bits are used.</p>
<p>Note: <a href="qimage.html#pixel">QImage::pixel</a>() returns the color of the pixel at the given coordinates while QColor::pixel() returns the pixel value of the underlying window system (essentially an index value), so normally you will want to use <a href="qimage.html#pixel">QImage::pixel</a>() to use a color from an existing image or <a href="qcolor.html#rgb">QColor::rgb</a>() to use a specific color.</p>
<p><b>See also </b><a href="qimage.html#depth">depth</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@fill -->
<!-- $$$fill$$$fillconstQColor& -->
<h3 class="fn" id="fill-1"><a name="fill-1"></a><span class="type">void</span> QImage::<span class="name">fill</span>(const <span class="type"><a href="qcolor.html">QColor</a></span> &amp;<i>color</i>)</h3>
<p>This is an overloaded function.</p>
<p>Fills the entire image with the given <i>color</i>.</p>
<p>If the depth of the image is 1, the image will be filled with 1 if <i>color</i> equals <a href="../qtcore/qt.html#GlobalColor-enum">Qt::color1</a>; it will otherwise be filled with 0.</p>
<p>If the depth of the image is 8, the image will be filled with the index corresponding the <i>color</i> in the color table if present; it will otherwise be filled with 0.</p>
<p>This function was introduced in Qt 4.8.</p>
<!-- @@@fill -->
<!-- $$$fill$$$fillQt::GlobalColor -->
<h3 class="fn" id="fill-2"><a name="fill-2"></a><span class="type">void</span> QImage::<span class="name">fill</span>(<span class="type"><a href="../qtcore/qt.html#GlobalColor-enum">Qt::GlobalColor</a></span> <i>color</i>)</h3>
<p>This is an overloaded function.</p>
<p>Fills the image with the given <i>color</i>, described as a standard global color.</p>
<p>This function was introduced in Qt 4.8.</p>
<!-- @@@fill -->
<!-- $$$format[overload1]$$$format -->
<h3 class="fn" id="format"><a name="format"></a><span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> QImage::<span class="name">format</span>() const</h3>
<p>Returns the format of the image.</p>
<p><b>See also </b><a href="qimage.html#image-formats">Image Formats</a>.</p>
<!-- @@@format -->
<!-- $$$fromData[overload1]$$$fromDataconstuchar*intconstchar* -->
<h3 class="fn" id="fromData"><a name="fromData"></a><code>[static] </code><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">fromData</span>(const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *<i>data</i>, <span class="type">int</span> <i>size</i>, const <span class="type">char</span> *<i>format</i> = nullptr)</h3>
<p>Constructs a <a href="qimage.html">QImage</a> from the first <i>size</i> bytes of the given binary <i>data</i>. The loader attempts to read the image using the specified <i>format</i>. If <i>format</i> is not specified (which is the default), the loader probes the data for a header to guess the file format.</p>
<p>If <i>format</i> is specified, it must be one of the values returned by <a href="qimagereader.html#supportedImageFormats">QImageReader::supportedImageFormats</a>().</p>
<p>If the loading of the image fails, the image returned will be a null image.</p>
<p><b>See also </b><a href="qimage.html#load">load</a>(), <a href="qimage.html#save">save</a>(), and <a href="qimage.html#reading-and-writing-image-files">Reading and Writing Image Files</a>.</p>
<!-- @@@fromData -->
<!-- $$$fromData$$$fromDataconstQByteArray&constchar* -->
<h3 class="fn" id="fromData-1"><a name="fromData-1"></a><code>[static] </code><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">fromData</span>(const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>data</i>, const <span class="type">char</span> *<i>format</i> = nullptr)</h3>
<p>This is an overloaded function.</p>
<p>Loads an image from the given <a href="../qtcore/qbytearray.html">QByteArray</a> <i>data</i>.</p>
<!-- @@@fromData -->
<!-- $$$hasAlphaChannel[overload1]$$$hasAlphaChannel -->
<h3 class="fn" id="hasAlphaChannel"><a name="hasAlphaChannel"></a><span class="type">bool</span> QImage::<span class="name">hasAlphaChannel</span>() const</h3>
<p>Returns <code>true</code> if the image has a format that respects the alpha channel, otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@hasAlphaChannel -->
<!-- $$$height[overload1]$$$height -->
<h3 class="fn" id="height"><a name="height"></a><span class="type">int</span> QImage::<span class="name">height</span>() const</h3>
<p>Returns the height of the image.</p>
<p><b>See also </b><a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@height -->
<!-- $$$invertPixels[overload1]$$$invertPixelsQImage::InvertMode -->
<h3 class="fn" id="invertPixels"><a name="invertPixels"></a><span class="type">void</span> QImage::<span class="name">invertPixels</span>(<span class="type"><a href="qimage.html#InvertMode-enum">QImage::InvertMode</a></span> <i>mode</i> = InvertRgb)</h3>
<p>Inverts all pixel values in the image.</p>
<p>The given invert <i>mode</i> only have a meaning when the image's depth is 32. The default <i>mode</i> is <a href="qimage.html#InvertMode-enum">InvertRgb</a>, which leaves the alpha channel unchanged. If the <i>mode</i> is <a href="qimage.html#InvertMode-enum">InvertRgba</a>, the alpha bits are also inverted.</p>
<p>Inverting an 8-bit image means to replace all pixels using color index <i>i</i> with a pixel using color index 255 minus <i>i</i>. The same is the case for a 1-bit image. Note that the color table is <i>not</i> changed.</p>
<p>If the image has a premultiplied alpha channel, the image is first converted to an unpremultiplied image format to be inverted and then converted back.</p>
<p><b>See also </b><a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@invertPixels -->
<!-- $$$isGrayscale[overload1]$$$isGrayscale -->
<h3 class="fn" id="isGrayscale"><a name="isGrayscale"></a><span class="type">bool</span> QImage::<span class="name">isGrayscale</span>() const</h3>
<p>For 32-bit images, this function is equivalent to <a href="qimage.html#allGray">allGray</a>().</p>
<p>For color indexed images, this function returns <code>true</code> if color(i) is <a href="qcolor.html#QRgb-typedef">QRgb</a>(i, i, i) for all indexes of the color table; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qimage.html#allGray">allGray</a>() and <a href="qimage.html#image-formats">Image Formats</a>.</p>
<!-- @@@isGrayscale -->
<!-- $$$isNull[overload1]$$$isNull -->
<h3 class="fn" id="isNull"><a name="isNull"></a><span class="type">bool</span> QImage::<span class="name">isNull</span>() const</h3>
<p>Returns <code>true</code> if it is a null image, otherwise returns <code>false</code>.</p>
<p>A null image has all parameters set to zero and no allocated data.</p>
<!-- @@@isNull -->
<!-- $$$load[overload1]$$$loadconstQString&constchar* -->
<h3 class="fn" id="load"><a name="load"></a><span class="type">bool</span> QImage::<span class="name">load</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>fileName</i>, const <span class="type">char</span> *<i>format</i> = nullptr)</h3>
<p>Loads an image from the file with the given <i>fileName</i>. Returns <code>true</code> if the image was successfully loaded; otherwise invalidates the image and returns <code>false</code>.</p>
<p>The loader attempts to read the image using the specified <i>format</i>, e.g&#x2e;, PNG or JPG. If <i>format</i> is not specified (which is the default), it is auto-detected based on the file's suffix and header. For details, see <a href="qimagereader.html#setAutoDetectImageFormat">QImageReader::setAutoDetectImageFormat</a>().</p>
<p>The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the <a href="../qtcore/resources.html">Resource System</a> overview for details on how to embed images and other resource files in the application's executable.</p>
<p><b>See also </b><a href="qimage.html#reading-and-writing-image-files">Reading and Writing Image Files</a>.</p>
<!-- @@@load -->
<!-- $$$load$$$loadQIODevice*constchar* -->
<h3 class="fn" id="load-1"><a name="load-1"></a><span class="type">bool</span> QImage::<span class="name">load</span>(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span> *<i>device</i>, const <span class="type">char</span> *<i>format</i>)</h3>
<p>This is an overloaded function.</p>
<p>This function reads a <a href="qimage.html">QImage</a> from the given <i>device</i>. This can, for example, be used to load an image directly into a <a href="../qtcore/qbytearray.html">QByteArray</a>.</p>
<!-- @@@load -->
<!-- $$$loadFromData[overload1]$$$loadFromDataconstuchar*intconstchar* -->
<h3 class="fn" id="loadFromData"><a name="loadFromData"></a><span class="type">bool</span> QImage::<span class="name">loadFromData</span>(const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *<i>data</i>, <span class="type">int</span> <i>len</i>, const <span class="type">char</span> *<i>format</i> = nullptr)</h3>
<p>Loads an image from the first <i>len</i> bytes of the given binary <i>data</i>. Returns <code>true</code> if the image was successfully loaded; otherwise invalidates the image and returns <code>false</code>.</p>
<p>The loader attempts to read the image using the specified <i>format</i>, e.g&#x2e;, PNG or JPG. If <i>format</i> is not specified (which is the default), the loader probes the file for a header to guess the file format.</p>
<p><b>See also </b><a href="qimage.html#reading-and-writing-image-files">Reading and Writing Image Files</a>.</p>
<!-- @@@loadFromData -->
<!-- $$$loadFromData$$$loadFromDataconstQByteArray&constchar* -->
<h3 class="fn" id="loadFromData-1"><a name="loadFromData-1"></a><span class="type">bool</span> QImage::<span class="name">loadFromData</span>(const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>data</i>, const <span class="type">char</span> *<i>format</i> = nullptr)</h3>
<p>This is an overloaded function.</p>
<p>Loads an image from the given <a href="../qtcore/qbytearray.html">QByteArray</a> <i>data</i>.</p>
<!-- @@@loadFromData -->
<!-- $$$offset[overload1]$$$offset -->
<h3 class="fn" id="offset"><a name="offset"></a><span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> QImage::<span class="name">offset</span>() const</h3>
<p>Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.</p>
<p><b>See also </b><a href="qimage.html#setOffset">setOffset</a>() and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@offset -->
<!-- $$$pixel[overload1]$$$pixelconstQPoint& -->
<h3 class="fn" id="pixel"><a name="pixel"></a><span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span> QImage::<span class="name">pixel</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &amp;<i>position</i>) const</h3>
<p>Returns the color of the pixel at the given <i>position</i>.</p>
<p>If the <i>position</i> is not valid, the results are undefined.</p>
<p><b>Warning:</b> This function is expensive when used for massive pixel manipulations. Use <a href="qimage.html#constBits">constBits</a>() or <a href="qimage.html#constScanLine">constScanLine</a>() when many pixels needs to be read.</p>
<p><b>See also </b><a href="qimage.html#setPixel">setPixel</a>(), <a href="qimage.html#valid">valid</a>(), <a href="qimage.html#constBits">constBits</a>(), <a href="qimage.html#constScanLine">constScanLine</a>(), and <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>.</p>
<!-- @@@pixel -->
<!-- $$$pixel$$$pixelintint -->
<h3 class="fn" id="pixel-1"><a name="pixel-1"></a><span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span> QImage::<span class="name">pixel</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>) const</h3>
<p>This is an overloaded function.</p>
<p>Returns the color of the pixel at coordinates (<i>x</i>, <i>y</i>).</p>
<!-- @@@pixel -->
<!-- $$$pixelColor[overload1]$$$pixelColorconstQPoint& -->
<h3 class="fn" id="pixelColor"><a name="pixelColor"></a><span class="type"><a href="qcolor.html">QColor</a></span> QImage::<span class="name">pixelColor</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &amp;<i>position</i>) const</h3>
<p>Returns the color of the pixel at the given <i>position</i> as a <a href="qcolor.html">QColor</a>.</p>
<p>If the <i>position</i> is not valid, an invalid <a href="qcolor.html">QColor</a> is returned.</p>
<p><b>Warning:</b> This function is expensive when used for massive pixel manipulations. Use <a href="qimage.html#constBits">constBits</a>() or <a href="qimage.html#constScanLine">constScanLine</a>() when many pixels needs to be read.</p>
<p>This function was introduced in Qt 5.6.</p>
<p><b>See also </b><a href="qimage.html#setPixelColor">setPixelColor</a>(), <a href="qimage.html#setPixel">setPixel</a>(), <a href="qimage.html#valid">valid</a>(), <a href="qimage.html#constBits">constBits</a>(), <a href="qimage.html#constScanLine">constScanLine</a>(), and <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>.</p>
<!-- @@@pixelColor -->
<!-- $$$pixelColor$$$pixelColorintint -->
<h3 class="fn" id="pixelColor-1"><a name="pixelColor-1"></a><span class="type"><a href="qcolor.html">QColor</a></span> QImage::<span class="name">pixelColor</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>) const</h3>
<p>This is an overloaded function.</p>
<p>Returns the color of the pixel at coordinates (<i>x</i>, <i>y</i>) as a <a href="qcolor.html">QColor</a>.</p>
<p>This function was introduced in Qt 5.6.</p>
<!-- @@@pixelColor -->
<!-- $$$pixelFormat[overload1]$$$pixelFormat -->
<h3 class="fn" id="pixelFormat"><a name="pixelFormat"></a><span class="type"><a href="qpixelformat.html">QPixelFormat</a></span> QImage::<span class="name">pixelFormat</span>() const</h3>
<p>Returns the <a href="qimage.html#Format-enum">QImage::Format</a> as a <a href="qpixelformat.html">QPixelFormat</a></p>
<!-- @@@pixelFormat -->
<!-- $$$pixelIndex[overload1]$$$pixelIndexconstQPoint& -->
<h3 class="fn" id="pixelIndex"><a name="pixelIndex"></a><span class="type">int</span> QImage::<span class="name">pixelIndex</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &amp;<i>position</i>) const</h3>
<p>Returns the pixel index at the given <i>position</i>.</p>
<p>If <i>position</i> is not valid, or if the image is not a paletted image (<a href="qimage.html#depth">depth</a>() &gt; 8), the results are undefined.</p>
<p><b>See also </b><a href="qimage.html#valid">valid</a>(), <a href="qimage.html#depth">depth</a>(), and <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>.</p>
<!-- @@@pixelIndex -->
<!-- $$$pixelIndex$$$pixelIndexintint -->
<h3 class="fn" id="pixelIndex-1"><a name="pixelIndex-1"></a><span class="type">int</span> QImage::<span class="name">pixelIndex</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>) const</h3>
<p>This is an overloaded function.</p>
<p>Returns the pixel index at (<i>x</i>, <i>y</i>).</p>
<!-- @@@pixelIndex -->
<!-- $$$rect[overload1]$$$rect -->
<h3 class="fn" id="rect"><a name="rect"></a><span class="type"><a href="../qtcore/qrect.html">QRect</a></span> QImage::<span class="name">rect</span>() const</h3>
<p>Returns the enclosing rectangle (0, 0, <a href="qimage.html#width">width</a>(), <a href="qimage.html#height">height</a>()) of the image.</p>
<p><b>See also </b><a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@rect -->
<!-- $$$reinterpretAsFormat[overload1]$$$reinterpretAsFormatQImage::Format -->
<h3 class="fn" id="reinterpretAsFormat"><a name="reinterpretAsFormat"></a><span class="type">bool</span> QImage::<span class="name">reinterpretAsFormat</span>(<span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>)</h3>
<p>Changes the format of the image to <i>format</i> without changing the data. Only works between formats of the same depth.</p>
<p>Returns <code>true</code> if successful.</p>
<p>This function can be used to change images with alpha-channels to their corresponding opaque formats if the data is known to be opaque-only, or to change the format of a given image buffer before overwriting it with new data.</p>
<p><b>Warning:</b> The function does not check if the image data is valid in the new format and will still return <code>true</code> if the depths are compatible. Operations on an image with invalid data are undefined.</p>
<p><b>Warning:</b> If the image is not detached, this will cause the data to be copied.</p>
<p>This function was introduced in Qt 5.9.</p>
<p><b>See also </b><a href="qimage.html#hasAlphaChannel">hasAlphaChannel</a>() and <a href="qimage.html#convertToFormat">convertToFormat</a>().</p>
<!-- @@@reinterpretAsFormat -->
<!-- $$$save[overload1]$$$saveconstQString&constchar*int -->
<h3 class="fn" id="save"><a name="save"></a><span class="type">bool</span> QImage::<span class="name">save</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>fileName</i>, const <span class="type">char</span> *<i>format</i> = nullptr, <span class="type">int</span> <i>quality</i> = -1) const</h3>
<p>Saves the image to the file with the given <i>fileName</i>, using the given image file <i>format</i> and <i>quality</i> factor. If <i>format</i> is 0, <a href="qimage.html">QImage</a> will attempt to guess the format by looking at <i>fileName</i>'s suffix.</p>
<p>The <i>quality</i> factor must be in the range 0 to 100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.</p>
<p>Returns <code>true</code> if the image was successfully saved; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qimage.html#reading-and-writing-image-files">Reading and Writing Image Files</a>.</p>
<!-- @@@save -->
<!-- $$$save$$$saveQIODevice*constchar*int -->
<h3 class="fn" id="save-1"><a name="save-1"></a><span class="type">bool</span> QImage::<span class="name">save</span>(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span> *<i>device</i>, const <span class="type">char</span> *<i>format</i> = nullptr, <span class="type">int</span> <i>quality</i> = -1) const</h3>
<p>This is an overloaded function.</p>
<p>This function writes a <a href="qimage.html">QImage</a> to the given <i>device</i>.</p>
<p>This can, for example, be used to save an image directly into a <a href="../qtcore/qbytearray.html">QByteArray</a>:</p>
<pre class="cpp">

          <span class="type"><a href="qimage.html#QImage">QImage</a></span> image;
          <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> ba;
          <span class="type"><a href="../qtcore/qbuffer.html">QBuffer</a></span> buffer(<span class="operator">&amp;</span>ba);
          buffer<span class="operator">.</span>open(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span><span class="operator">::</span>WriteOnly);
          image<span class="operator">.</span>save(<span class="operator">&amp;</span>buffer<span class="operator">,</span> <span class="string">&quot;PNG&quot;</span>); <span class="comment">// writes image into ba in PNG format</span>

</pre>
<!-- @@@save -->
<!-- $$$scaled[overload1]$$$scaledconstQSize&Qt::AspectRatioModeQt::TransformationMode -->
<h3 class="fn" id="scaled"><a name="scaled"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">scaled</span>(const <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> &amp;<i>size</i>, <span class="type"><a href="../qtcore/qt.html#AspectRatioMode-enum">Qt::AspectRatioMode</a></span> <i>aspectRatioMode</i> = Qt::IgnoreAspectRatio, <span class="type"><a href="../qtcore/qt.html#TransformationMode-enum">Qt::TransformationMode</a></span> <i>transformMode</i> = Qt::FastTransformation) const</h3>
<p>Returns a copy of the image scaled to a rectangle defined by the given <i>size</i> according to the given <i>aspectRatioMode</i> and <i>transformMode</i>.</p>
<p class="centerAlign"><img src="images/qimage-scaling.png" alt="" /></p><ul>
<li>If <i>aspectRatioMode</i> is <a href="../qtcore/qt.html#AspectRatioMode-enum">Qt::IgnoreAspectRatio</a>, the image is scaled to <i>size</i>.</li>
<li>If <i>aspectRatioMode</i> is <a href="../qtcore/qt.html#AspectRatioMode-enum">Qt::KeepAspectRatio</a>, the image is scaled to a rectangle as large as possible inside <i>size</i>, preserving the aspect ratio.</li>
<li>If <i>aspectRatioMode</i> is <a href="../qtcore/qt.html#AspectRatioMode-enum">Qt::KeepAspectRatioByExpanding</a>, the image is scaled to a rectangle as small as possible outside <i>size</i>, preserving the aspect ratio.</li>
</ul>
<p>If the given <i>size</i> is empty, this function returns a null image.</p>
<p><b>See also </b><a href="qimage.html#isNull">isNull</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@scaled -->
<!-- $$$scaled$$$scaledintintQt::AspectRatioModeQt::TransformationMode -->
<h3 class="fn" id="scaled-1"><a name="scaled-1"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">scaled</span>(<span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>, <span class="type"><a href="../qtcore/qt.html#AspectRatioMode-enum">Qt::AspectRatioMode</a></span> <i>aspectRatioMode</i> = Qt::IgnoreAspectRatio, <span class="type"><a href="../qtcore/qt.html#TransformationMode-enum">Qt::TransformationMode</a></span> <i>transformMode</i> = Qt::FastTransformation) const</h3>
<p>This is an overloaded function.</p>
<p>Returns a copy of the image scaled to a rectangle with the given <i>width</i> and <i>height</i> according to the given <i>aspectRatioMode</i> and <i>transformMode</i>.</p>
<p>If either the <i>width</i> or the <i>height</i> is zero or negative, this function returns a null image.</p>
<!-- @@@scaled -->
<!-- $$$scaledToHeight[overload1]$$$scaledToHeightintQt::TransformationMode -->
<h3 class="fn" id="scaledToHeight"><a name="scaledToHeight"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">scaledToHeight</span>(<span class="type">int</span> <i>height</i>, <span class="type"><a href="../qtcore/qt.html#TransformationMode-enum">Qt::TransformationMode</a></span> <i>mode</i> = Qt::FastTransformation) const</h3>
<p>Returns a scaled copy of the image. The returned image is scaled to the given <i>height</i> using the specified transformation <i>mode</i>.</p>
<p>This function automatically calculates the width of the image so that the ratio of the image is preserved.</p>
<p>If the given <i>height</i> is 0 or negative, a null image is returned.</p>
<p><b>See also </b><a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@scaledToHeight -->
<!-- $$$scaledToWidth[overload1]$$$scaledToWidthintQt::TransformationMode -->
<h3 class="fn" id="scaledToWidth"><a name="scaledToWidth"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">scaledToWidth</span>(<span class="type">int</span> <i>width</i>, <span class="type"><a href="../qtcore/qt.html#TransformationMode-enum">Qt::TransformationMode</a></span> <i>mode</i> = Qt::FastTransformation) const</h3>
<p>Returns a scaled copy of the image. The returned image is scaled to the given <i>width</i> using the specified transformation <i>mode</i>.</p>
<p>This function automatically calculates the height of the image so that its aspect ratio is preserved.</p>
<p>If the given <i>width</i> is 0 or negative, a null image is returned.</p>
<p><b>See also </b><a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@scaledToWidth -->
<!-- $$$scanLine[overload1]$$$scanLineint -->
<h3 class="fn" id="scanLine"><a name="scanLine"></a><span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *QImage::<span class="name">scanLine</span>(<span class="type">int</span> <i>i</i>)</h3>
<p>Returns a pointer to the pixel data at the scanline with index <i>i</i>. The first scanline is at index 0.</p>
<p>The scanline data is as minimum 32-bit aligned. For 64-bit formats it follows the native alignment of 64-bit integers (64-bit for most platforms, but notably 32-bit on i386).</p>
<p><b>Warning:</b> If you are accessing 32-bpp image data, cast the returned pointer to <code>QRgb*</code> (<a href="qcolor.html#QRgb-typedef">QRgb</a> has a 32-bit size) and use it to read/write the pixel value. You cannot use the <code>uchar*</code> pointer directly, because the pixel format depends on the byte order on the underlying platform. Use <a href="qcolor.html#qRed">qRed</a>(), <a href="qcolor.html#qGreen">qGreen</a>(), <a href="qcolor.html#qBlue">qBlue</a>(), and <a href="qcolor.html#qAlpha">qAlpha</a>() to access the pixels.</p>
<p><b>See also </b><a href="qimage.html#bytesPerLine">bytesPerLine</a>(), <a href="qimage.html#bits">bits</a>(), <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>, and <a href="qimage.html#constScanLine">constScanLine</a>().</p>
<!-- @@@scanLine -->
<!-- $$$scanLine$$$scanLineint -->
<h3 class="fn" id="scanLine-1"><a name="scanLine-1"></a>const <span class="type"><a href="../qtcore/qtglobal.html#uchar-typedef">uchar</a></span> *QImage::<span class="name">scanLine</span>(<span class="type">int</span> <i>i</i>) const</h3>
<p>This is an overloaded function.</p>
<!-- @@@scanLine -->
<!-- $$$setColor[overload1]$$$setColorintQRgb -->
<h3 class="fn" id="setColor"><a name="setColor"></a><span class="type">void</span> QImage::<span class="name">setColor</span>(<span class="type">int</span> <i>index</i>, <span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span> <i>colorValue</i>)</h3>
<p>Sets the color at the given <i>index</i> in the color table, to the given to <i>colorValue</i>. The color value is an ARGB quadruplet.</p>
<p>If <i>index</i> is outside the current size of the color table, it is expanded with <a href="qimage.html#setColorCount">setColorCount</a>().</p>
<p><b>See also </b><a href="qimage.html#color">color</a>(), <a href="qimage.html#colorCount">colorCount</a>(), <a href="qimage.html#setColorTable">setColorTable</a>(), and <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>.</p>
<!-- @@@setColor -->
<!-- $$$setColorCount[overload1]$$$setColorCountint -->
<h3 class="fn" id="setColorCount"><a name="setColorCount"></a><span class="type">void</span> QImage::<span class="name">setColorCount</span>(<span class="type">int</span> <i>colorCount</i>)</h3>
<p>Resizes the color table to contain <i>colorCount</i> entries.</p>
<p>If the color table is expanded, all the extra colors will be set to transparent (i.e <a href="qcolor.html#qRgba">qRgba</a>(0, 0, 0, 0)).</p>
<p>When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also </b><a href="qimage.html#colorCount">colorCount</a>(), <a href="qimage.html#colorTable">colorTable</a>(), <a href="qimage.html#setColor">setColor</a>(), and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@setColorCount -->
<!-- $$$setColorSpace[overload1]$$$setColorSpaceconstQColorSpace& -->
<h3 class="fn" id="setColorSpace"><a name="setColorSpace"></a><span class="type">void</span> QImage::<span class="name">setColorSpace</span>(const <span class="type"><a href="qcolorspace.html">QColorSpace</a></span> &amp;<i>colorSpace</i>)</h3>
<p>Sets the image color space to <i>colorSpace</i> without performing any conversions on image data.</p>
<p>This function was introduced in Qt 5.14.</p>
<p><b>See also </b><a href="qimage.html#colorSpace">colorSpace</a>().</p>
<!-- @@@setColorSpace -->
<!-- $$$setColorTable[overload1]$$$setColorTableconstQVector<QRgb> -->
<h3 class="fn" id="setColorTable"><a name="setColorTable"></a><span class="type">void</span> QImage::<span class="name">setColorTable</span>(const <span class="type"><a href="../qtcore/qvector.html">QVector</a></span>&lt;<span class="type"><a href="qcolor.html#QRgb-typedef">QRgb</a></span>&gt; <i>colors</i>)</h3>
<p>Sets the color table used to translate color indexes to <a href="qcolor.html#QRgb-typedef">QRgb</a> values, to the specified <i>colors</i>.</p>
<p>When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.</p>
<p><b>See also </b><a href="qimage.html#colorTable">colorTable</a>(), <a href="qimage.html#setColor">setColor</a>(), and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@setColorTable -->
<!-- $$$setDevicePixelRatio[overload1]$$$setDevicePixelRatioqreal -->
<h3 class="fn" id="setDevicePixelRatio"><a name="setDevicePixelRatio"></a><span class="type">void</span> QImage::<span class="name">setDevicePixelRatio</span>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>scaleFactor</i>)</h3>
<p>Sets the device pixel ratio for the image. This is the ratio between image pixels and device-independent pixels.</p>
<p>The default <i>scaleFactor</i> is 1.0&#x2e; Setting it to something else has two effects:</p>
<p>QPainters that are opened on the image will be scaled. For example, painting on a 200x200 image if with a ratio of 2.0 will result in effective (device-independent) painting bounds of 100x100.</p>
<p>Code paths in Qt that calculate layout geometry based on the image size will take the ratio into account: <a href="../qtcore/qsize.html">QSize</a> layoutSize = image.<a href="qimage.html#size">size</a>() / image.<a href="qimage.html#devicePixelRatio">devicePixelRatio</a>() The net effect of this is that the image is displayed as high-DPI image rather than a large image (see <a href="qpainter.html#drawing-high-resolution-versions-of-pixmaps-and-images">Drawing High Resolution Versions of Pixmaps and Images</a>).</p>
<p><b>See also </b><a href="qimage.html#devicePixelRatio">devicePixelRatio</a>().</p>
<!-- @@@setDevicePixelRatio -->
<!-- $$$setDotsPerMeterX[overload1]$$$setDotsPerMeterXint -->
<h3 class="fn" id="setDotsPerMeterX"><a name="setDotsPerMeterX"></a><span class="type">void</span> QImage::<span class="name">setDotsPerMeterX</span>(<span class="type">int</span> <i>x</i>)</h3>
<p>Sets the number of pixels that fit horizontally in a physical meter, to <i>x</i>.</p>
<p>Together with <a href="qimage.html#dotsPerMeterY">dotsPerMeterY</a>(), this number defines the intended scale and aspect ratio of the image, and determines the scale at which <a href="qpainter.html">QPainter</a> will draw graphics on the image. It does not change the scale or aspect ratio of the image when it is rendered on other paint devices.</p>
<p><b>See also </b><a href="qimage.html#dotsPerMeterX">dotsPerMeterX</a>() and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@setDotsPerMeterX -->
<!-- $$$setDotsPerMeterY[overload1]$$$setDotsPerMeterYint -->
<h3 class="fn" id="setDotsPerMeterY"><a name="setDotsPerMeterY"></a><span class="type">void</span> QImage::<span class="name">setDotsPerMeterY</span>(<span class="type">int</span> <i>y</i>)</h3>
<p>Sets the number of pixels that fit vertically in a physical meter, to <i>y</i>.</p>
<p>Together with <a href="qimage.html#dotsPerMeterX">dotsPerMeterX</a>(), this number defines the intended scale and aspect ratio of the image, and determines the scale at which <a href="qpainter.html">QPainter</a> will draw graphics on the image. It does not change the scale or aspect ratio of the image when it is rendered on other paint devices.</p>
<p><b>See also </b><a href="qimage.html#dotsPerMeterY">dotsPerMeterY</a>() and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@setDotsPerMeterY -->
<!-- $$$setOffset[overload1]$$$setOffsetconstQPoint& -->
<h3 class="fn" id="setOffset"><a name="setOffset"></a><span class="type">void</span> QImage::<span class="name">setOffset</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &amp;<i>offset</i>)</h3>
<p>Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to <i>offset</i>.</p>
<p><b>See also </b><a href="qimage.html#offset">offset</a>() and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@setOffset -->
<!-- $$$setPixel[overload1]$$$setPixelconstQPoint&uint -->
<h3 class="fn" id="setPixel"><a name="setPixel"></a><span class="type">void</span> QImage::<span class="name">setPixel</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &amp;<i>position</i>, <span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> <i>index_or_rgb</i>)</h3>
<p>Sets the pixel index or color at the given <i>position</i> to <i>index_or_rgb</i>.</p>
<p>If the image's format is either monochrome or paletted, the given <i>index_or_rgb</i> value must be an index in the image's color table, otherwise the parameter must be a <a href="qcolor.html#QRgb-typedef">QRgb</a> value.</p>
<p>If <i>position</i> is not a valid coordinate pair in the image, or if <i>index_or_rgb</i> &gt;= <a href="qimage.html#colorCount">colorCount</a>() in the case of monochrome and paletted images, the result is undefined.</p>
<p><b>Warning:</b> This function is expensive due to the call of the internal <code>detach()</code> function called within; if performance is a concern, we recommend the use of <a href="qimage.html#scanLine">scanLine</a>() or <a href="qimage.html#bits">bits</a>() to access pixel data directly.</p>
<p><b>See also </b><a href="qimage.html#pixel">pixel</a>() and <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>.</p>
<!-- @@@setPixel -->
<!-- $$$setPixel$$$setPixelintintuint -->
<h3 class="fn" id="setPixel-1"><a name="setPixel-1"></a><span class="type">void</span> QImage::<span class="name">setPixel</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>, <span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> <i>index_or_rgb</i>)</h3>
<p>This is an overloaded function.</p>
<p>Sets the pixel index or color at (<i>x</i>, <i>y</i>) to <i>index_or_rgb</i>.</p>
<!-- @@@setPixel -->
<!-- $$$setPixelColor[overload1]$$$setPixelColorconstQPoint&constQColor& -->
<h3 class="fn" id="setPixelColor"><a name="setPixelColor"></a><span class="type">void</span> QImage::<span class="name">setPixelColor</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &amp;<i>position</i>, const <span class="type"><a href="qcolor.html">QColor</a></span> &amp;<i>color</i>)</h3>
<p>Sets the color at the given <i>position</i> to <i>color</i>.</p>
<p>If <i>position</i> is not a valid coordinate pair in the image, or the image's format is either monochrome or paletted, the result is undefined.</p>
<p><b>Warning:</b> This function is expensive due to the call of the internal <code>detach()</code> function called within; if performance is a concern, we recommend the use of <a href="qimage.html#scanLine">scanLine</a>() or <a href="qimage.html#bits">bits</a>() to access pixel data directly.</p>
<p>This function was introduced in Qt 5.6.</p>
<p><b>See also </b><a href="qimage.html#pixelColor">pixelColor</a>(), <a href="qimage.html#pixel">pixel</a>(), <a href="qimage.html#bits">bits</a>(), <a href="qimage.html#scanLine">scanLine</a>(), and <a href="qimage.html#pixel-manipulation">Pixel Manipulation</a>.</p>
<!-- @@@setPixelColor -->
<!-- $$$setPixelColor$$$setPixelColorintintconstQColor& -->
<h3 class="fn" id="setPixelColor-1"><a name="setPixelColor-1"></a><span class="type">void</span> QImage::<span class="name">setPixelColor</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>, const <span class="type"><a href="qcolor.html">QColor</a></span> &amp;<i>color</i>)</h3>
<p>This is an overloaded function.</p>
<p>Sets the pixel color at (<i>x</i>, <i>y</i>) to <i>color</i>.</p>
<p>This function was introduced in Qt 5.6.</p>
<!-- @@@setPixelColor -->
<!-- $$$setText[overload1]$$$setTextconstQString&constQString& -->
<h3 class="fn" id="setText"><a name="setText"></a><span class="type">void</span> QImage::<span class="name">setText</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>key</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>text</i>)</h3>
<p>Sets the image text to the given <i>text</i> and associate it with the given <i>key</i>.</p>
<p>If you just want to store a single text block (i.e&#x2e;, a &quot;comment&quot; or just a description), you can either pass an empty key, or use a generic key like &quot;Description&quot;.</p>
<p>The image text is embedded into the image data when you call <a href="qimage.html#save">save</a>() or <a href="qimagewriter.html#write">QImageWriter::write</a>().</p>
<p>Not all image formats support embedded text. You can find out if a specific image or format supports embedding text by using <a href="qimagewriter.html#supportsOption">QImageWriter::supportsOption</a>(). We give an example:</p>
<pre class="cpp">

      <span class="type"><a href="qimagewriter.html">QImageWriter</a></span> writer;
      writer<span class="operator">.</span>setFormat(<span class="string">&quot;png&quot;</span>);
      <span class="keyword">if</span> (writer<span class="operator">.</span>supportsOption(<span class="type"><a href="qimageiohandler.html">QImageIOHandler</a></span><span class="operator">::</span>Description))
          <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Png supports embedded text&quot;</span>;

</pre>
<p>You can use <a href="qimagewriter.html#supportedImageFormats">QImageWriter::supportedImageFormats</a>() to find out which image formats are available to you.</p>
<p><b>See also </b><a href="qimage.html#text">text</a>() and <a href="qimage.html#textKeys">textKeys</a>().</p>
<!-- @@@setText -->
<!-- $$$size[overload1]$$$size -->
<h3 class="fn" id="size"><a name="size"></a><span class="type"><a href="../qtcore/qsize.html">QSize</a></span> QImage::<span class="name">size</span>() const</h3>
<p>Returns the size of the image, i.e&#x2e; its <a href="qimage.html#width">width</a>() and <a href="qimage.html#height">height</a>().</p>
<p><b>See also </b><a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@size -->
<!-- $$$sizeInBytes[overload1]$$$sizeInBytes -->
<h3 class="fn" id="sizeInBytes"><a name="sizeInBytes"></a><span class="type">qsizetype</span> QImage::<span class="name">sizeInBytes</span>() const</h3>
<p>Returns the image data size in bytes.</p>
<p>This function was introduced in Qt 5.10.</p>
<p><b>See also </b><a href="qimage-obsolete.html#byteCount">byteCount</a>(), <a href="qimage.html#bytesPerLine">bytesPerLine</a>(), <a href="qimage.html#bits">bits</a>(), and <a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@sizeInBytes -->
<!-- $$$smoothScaled[overload1]$$$smoothScaledintint -->
<h3 class="fn" id="smoothScaled"><a name="smoothScaled"></a><code>[protected] </code><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">smoothScaled</span>(<span class="type">int</span> <i>w</i>, <span class="type">int</span> <i>h</i>) const</h3>
<p>Returns a smoothly scaled copy of the image. The returned image has a size of width <i>w</i> by height <i>h</i> pixels.</p>
<!-- @@@smoothScaled -->
<!-- $$$swap[overload1]$$$swapQImage& -->
<h3 class="fn" id="swap"><a name="swap"></a><span class="type">void</span> QImage::<span class="name">swap</span>(<span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;<i>other</i>)</h3>
<p>Swaps image <i>other</i> with this image. This operation is very fast and never fails.</p>
<p>This function was introduced in Qt 4.8.</p>
<!-- @@@swap -->
<!-- $$$text[overload1]$$$textconstQString& -->
<h3 class="fn" id="text"><a name="text"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QImage::<span class="name">text</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>key</i> = QString()) const</h3>
<p>Returns the image text associated with the given <i>key</i>. If the specified <i>key</i> is an empty string, the whole image text is returned, with each key-text pair separated by a newline.</p>
<p><b>See also </b><a href="qimage.html#setText">setText</a>() and <a href="qimage.html#textKeys">textKeys</a>().</p>
<!-- @@@text -->
<!-- $$$textKeys[overload1]$$$textKeys -->
<h3 class="fn" id="textKeys"><a name="textKeys"></a><span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> QImage::<span class="name">textKeys</span>() const</h3>
<p>Returns the text keys for this image.</p>
<p>You can use these keys with <a href="qimage.html#text">text</a>() to list the image text for a certain key.</p>
<p><b>See also </b><a href="qimage.html#text">text</a>().</p>
<!-- @@@textKeys -->
<!-- $$$toCGImage[overload1]$$$toCGImage -->
<h3 class="fn" id="toCGImage"><a name="toCGImage"></a><span class="type">CGImageRef</span> QImage::<span class="name">toCGImage</span>() const</h3>
<p>Creates a <code>CGImage</code> equivalent to this <a href="qimage.html">QImage</a>. Returns a <code>CGImageRef</code> handle.</p>
<p>The returned CGImageRef partakes in the <a href="qimage.html">QImage</a> implicit sharing, and holds a reference to the <a href="qimage.html">QImage</a> data. CGImage is immutable and will never detach the <a href="qimage.html">QImage</a>. Writing to the <a href="qimage.html">QImage</a> will detach as usual.</p>
<p>This function is fast, and does not copy or convert image data.</p>
<p>The following image formats are supported, and will be mapped to a corresponding native image type:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Qt</th><th >CoreGraphics</th></tr></thead>
<tr valign="top" class="odd"><td ><a href="qimage.html#Format-enum">Format_ARGB32</a></td><td >kCGImageAlphaFirst | kCGBitmapByteOrder32Host</td></tr>
<tr valign="top" class="even"><td ><a href="qimage.html#Format-enum">Format_RGB32</a></td><td >kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host</td></tr>
<tr valign="top" class="odd"><td ><a href="qimage.html#Format-enum">Format_RGBA8888_Premultiplied</a></td><td >kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big</td></tr>
<tr valign="top" class="even"><td ><a href="qimage.html#Format-enum">Format_RGBA8888</a></td><td >kCGImageAlphaLast | kCGBitmapByteOrder32Big</td></tr>
<tr valign="top" class="odd"><td ><a href="qimage.html#Format-enum">Format_RGBX8888</a></td><td >kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big</td></tr>
<tr valign="top" class="even"><td ><a href="qimage.html#Format-enum">Format_ARGB32_Premultiplied</a></td><td >kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host</td></tr>
</table></div>
<p>Other formats are not supported; this function returns a null CGImageRef for those cases. Users of this function may then convert the <a href="qimage.html">QImage</a> to a supported formate first, for example <a href="qimage.html#Format-enum">Format_ARGB32_Premultiplied</a>.</p>
<p>The CGImageRef color space is set to the sRGB color space.</p>
<p><b>See also </b><a href="../qtmacextras/qtmac.html#toNSImage">QtMac::toNSImage</a>().</p>
<!-- @@@toCGImage -->
<!-- $$$toImageFormat[overload1]$$$toImageFormatQPixelFormat -->
<h3 class="fn" id="toImageFormat"><a name="toImageFormat"></a><code>[static] </code><span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> QImage::<span class="name">toImageFormat</span>(<span class="type"><a href="qpixelformat.html">QPixelFormat</a></span> <i>format</i>)</h3>
<p>Converts <i>format</i> into a <a href="qimage.html#Format-enum">QImage::Format</a></p>
<!-- @@@toImageFormat -->
<!-- $$$toPixelFormat[overload1]$$$toPixelFormatQImage::Format -->
<h3 class="fn" id="toPixelFormat"><a name="toPixelFormat"></a><code>[static] </code><span class="type"><a href="qpixelformat.html">QPixelFormat</a></span> QImage::<span class="name">toPixelFormat</span>(<span class="type"><a href="qimage.html#Format-enum">QImage::Format</a></span> <i>format</i>)</h3>
<p>Converts <i>format</i> into a <a href="qpixelformat.html">QPixelFormat</a></p>
<!-- @@@toPixelFormat -->
<!-- $$$transformed[overload1]$$$transformedconstQMatrix&Qt::TransformationMode -->
<h3 class="fn" id="transformed"><a name="transformed"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">transformed</span>(const <span class="type"><a href="qmatrix.html">QMatrix</a></span> &amp;<i>matrix</i>, <span class="type"><a href="../qtcore/qt.html#TransformationMode-enum">Qt::TransformationMode</a></span> <i>mode</i> = Qt::FastTransformation) const</h3>
<p>Returns a copy of the image that is transformed using the given transformation <i>matrix</i> and transformation <i>mode</i>.</p>
<p>The returned image will normally have the same {Image Formats}{format} as the original image. However, a complex transformation may result in an image where not all pixels are covered by the transformed pixels of the original image. In such cases, those background pixels will be assigned a transparent color value, and the transformed image will be given a format with an alpha channel, even if the orginal image did not have that.</p>
<p>The transformation <i>matrix</i> is internally adjusted to compensate for unwanted translation; i.e&#x2e; the image produced is the smallest image that contains all the transformed points of the original image. Use the <a href="qimage.html#trueMatrix">trueMatrix</a>() function to retrieve the actual matrix used for transforming an image.</p>
<p><b>See also </b><a href="qimage.html#trueMatrix">trueMatrix</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@transformed -->
<!-- $$$transformed$$$transformedconstQTransform&Qt::TransformationMode -->
<h3 class="fn" id="transformed-1"><a name="transformed-1"></a><span class="type"><a href="qimage.html#QImage">QImage</a></span> QImage::<span class="name">transformed</span>(const <span class="type"><a href="qtransform.html">QTransform</a></span> &amp;<i>matrix</i>, <span class="type"><a href="../qtcore/qt.html#TransformationMode-enum">Qt::TransformationMode</a></span> <i>mode</i> = Qt::FastTransformation) const</h3>
<p>Returns a copy of the image that is transformed using the given transformation <i>matrix</i> and transformation <i>mode</i>.</p>
<p>The returned image will normally have the same {Image Formats}{format} as the original image. However, a complex transformation may result in an image where not all pixels are covered by the transformed pixels of the original image. In such cases, those background pixels will be assigned a transparent color value, and the transformed image will be given a format with an alpha channel, even if the orginal image did not have that.</p>
<p>The transformation <i>matrix</i> is internally adjusted to compensate for unwanted translation; i.e&#x2e; the image produced is the smallest image that contains all the transformed points of the original image. Use the <a href="qimage.html#trueMatrix">trueMatrix</a>() function to retrieve the actual matrix used for transforming an image.</p>
<p>Unlike the other overload, this function can be used to perform perspective transformations on images.</p>
<p><b>See also </b><a href="qimage.html#trueMatrix">trueMatrix</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@transformed -->
<!-- $$$trueMatrix[overload1]$$$trueMatrixconstQMatrix&intint -->
<h3 class="fn" id="trueMatrix"><a name="trueMatrix"></a><code>[static] </code><span class="type"><a href="qmatrix.html">QMatrix</a></span> QImage::<span class="name">trueMatrix</span>(const <span class="type"><a href="qmatrix.html">QMatrix</a></span> &amp;<i>matrix</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>)</h3>
<p>Returns the actual matrix used for transforming an image with the given <i>width</i>, <i>height</i> and <i>matrix</i>.</p>
<p>When transforming an image using the <a href="qimage.html#transformed">transformed</a>() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e&#x2e; <a href="qimage.html#transformed">transformed</a>() returns the smallest image containing all transformed points of the original image. This function returns the modified matrix, which maps points correctly from the original image into the new image.</p>
<p><b>See also </b><a href="qimage.html#transformed">transformed</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@trueMatrix -->
<!-- $$$trueMatrix$$$trueMatrixconstQTransform&intint -->
<h3 class="fn" id="trueMatrix-1"><a name="trueMatrix-1"></a><code>[static] </code><span class="type"><a href="qtransform.html">QTransform</a></span> QImage::<span class="name">trueMatrix</span>(const <span class="type"><a href="qtransform.html">QTransform</a></span> &amp;<i>matrix</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>)</h3>
<p>Returns the actual matrix used for transforming an image with the given <i>width</i>, <i>height</i> and <i>matrix</i>.</p>
<p>When transforming an image using the <a href="qimage.html#transformed">transformed</a>() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e&#x2e; <a href="qimage.html#transformed">transformed</a>() returns the smallest image containing all transformed points of the original image. This function returns the modified matrix, which maps points correctly from the original image into the new image.</p>
<p>Unlike the other overload, this function creates transformation matrices that can be used to perform perspective transformations on images.</p>
<p><b>See also </b><a href="qimage.html#transformed">transformed</a>() and <a href="qimage.html#image-transformations">Image Transformations</a>.</p>
<!-- @@@trueMatrix -->
<!-- $$$valid[overload1]$$$validconstQPoint& -->
<h3 class="fn" id="valid"><a name="valid"></a><span class="type">bool</span> QImage::<span class="name">valid</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &amp;<i>pos</i>) const</h3>
<p>Returns <code>true</code> if <i>pos</i> is a valid coordinate pair within the image; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qimage.html#rect">rect</a>() and <a href="../qtcore/qrect.html#contains">QRect::contains</a>().</p>
<!-- @@@valid -->
<!-- $$$valid$$$validintint -->
<h3 class="fn" id="valid-1"><a name="valid-1"></a><span class="type">bool</span> QImage::<span class="name">valid</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>) const</h3>
<p>This is an overloaded function.</p>
<p>Returns <code>true</code> if <a href="../qtcore/qpoint.html">QPoint</a>(<i>x</i>, <i>y</i>) is a valid coordinate pair within the image; otherwise returns <code>false</code>.</p>
<!-- @@@valid -->
<!-- $$$width[overload1]$$$width -->
<h3 class="fn" id="width"><a name="width"></a><span class="type">int</span> QImage::<span class="name">width</span>() const</h3>
<p>Returns the width of the image.</p>
<p><b>See also </b><a href="qimage.html#image-information">Image Information</a>.</p>
<!-- @@@width -->
<!-- $$$operator QVariant[overload1]$$$operator QVariant -->
<h3 class="fn" id="operator-QVariant"><a name="operator-QVariant"></a><span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span> QImage::<span class="name">operator QVariant</span>() const</h3>
<p>Returns the image as a <a href="../qtcore/qvariant.html">QVariant</a>.</p>
<!-- @@@operator QVariant -->
<!-- $$$operator!=[overload1]$$$operator!=constQImage& -->
<h3 class="fn" id="operator-not-eq"><a name="operator-not-eq"></a><span class="type">bool</span> QImage::<span class="name">operator!=</span>(const <span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;<i>image</i>) const</h3>
<p>Returns <code>true</code> if this image and the given <i>image</i> have different contents; otherwise returns <code>false</code>.</p>
<p>The comparison can be slow, unless there is some obvious difference, such as different widths, in which case the function will return quickly.</p>
<p><b>See also </b><a href="qimage.html#operator-eq">operator=</a>().</p>
<!-- @@@operator!= -->
<!-- $$$operator==[overload1]$$$operator==constQImage& -->
<h3 class="fn" id="operator-eq-eq"><a name="operator-eq-eq"></a><span class="type">bool</span> QImage::<span class="name">operator==</span>(const <span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;<i>image</i>) const</h3>
<p>Returns <code>true</code> if this image and the given <i>image</i> have the same contents; otherwise returns <code>false</code>.</p>
<p>The comparison can be slow, unless there is some obvious difference (e.g&#x2e; different size or format), in which case the function will return quickly.</p>
<p><b>See also </b><a href="qimage.html#operator-eq">operator=</a>().</p>
<!-- @@@operator== -->
</div>
<div class="relnonmem">
<h2>Related Non-Members</h2>
<!-- $$$QImageCleanupFunction -->
<h3 class="fn" id="QImageCleanupFunction-typedef"><a name="QImageCleanupFunction-typedef"></a>typedef <span class="name">QImageCleanupFunction</span></h3>
<p>A function with the following signature that can be used to implement basic image memory management:</p>
<pre class="cpp">

  <span class="type">void</span> myImageCleanupHandler(<span class="type">void</span> <span class="operator">*</span>info);

</pre>
<p>This typedef was introduced in Qt 5.0.</p>
<!-- @@@QImageCleanupFunction -->
<!-- $$$operator<<$$$operator<<QDataStream&constQImage& -->
<h3 class="fn" id="operator-lt-lt-23"><a name="operator-lt-lt-23"></a><span class="type"><a href="../qtcore/qdatastream.html">QDataStream</a></span> &amp;<span class="name">operator&lt;&lt;</span>(<span class="type"><a href="../qtcore/qdatastream.html">QDataStream</a></span> &amp;<i>stream</i>, const <span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;<i>image</i>)</h3>
<p>Writes the given <i>image</i> to the given <i>stream</i> as a PNG image, or as a BMP image if the stream's version is 1. Note that writing the stream to a file will not produce a valid image file.</p>
<p><b>See also </b><a href="qimage.html#save">QImage::save</a>() and <a href="../qtcore/datastreamformat.html">Serializing Qt Data Types</a>.</p>
<!-- @@@operator<< -->
<!-- $$$operator>>[overload1]$$$operator>>QDataStream&QImage& -->
<h3 class="fn" id="operator-gt-gt"><a name="operator-gt-gt"></a><span class="type"><a href="../qtcore/qdatastream.html">QDataStream</a></span> &amp;<span class="name">operator&gt;&gt;</span>(<span class="type"><a href="../qtcore/qdatastream.html">QDataStream</a></span> &amp;<i>stream</i>, <span class="type"><a href="qimage.html#QImage">QImage</a></span> &amp;<i>image</i>)</h3>
<p>Reads an image from the given <i>stream</i> and stores it in the given <i>image</i>.</p>
<p><b>See also </b><a href="qimage.html#load">QImage::load</a>() and <a href="../qtcore/datastreamformat.html">Serializing Qt Data Types</a>.</p>
<!-- @@@operator>> -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
